CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Individual Prefix as an auto-complete text field?
Pages: [1]

Author Topic: Individual Prefix as an auto-complete text field?  (Read 1062 times)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Individual Prefix as an auto-complete text field?
April 17, 2010, 10:47:35 am
Hi All,

For my current project I need to allow the user to enter anything in the Individual Prefix field, rather than choosing from a list of options.  The client in this case is very sensitive about presenting the individual's honorific just as the individual wants, so "Dr.," "Rev. Dr.," and "Most Rt. Rev. Dr." should all be possible, along with anything else the user wants to enter. 

To illustrate the scope of issue: out of the aprox. 20K records in the client's existing database, there are over 400 distinct values for this field.  A select list that long is unwieldy in numerous ways.

What I'd really like is to present the field as a text input that offers type-ahead auto-complete for a short list of preferred options, but still allows the user to enter whatever they want.

My best idea so far is this:
1. Use hook_civicrm_buildForm to replace the existing select element with a text element,
2. Add some JS to the template for the type-ahead effect, and
3. Use hook_civicrm_postProcess to create -- if necessary -- an option for any new user-generated prefix.

Would anyone like to suggest a better way to do this? 

Thanks,
Allen
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Individual Prefix as an auto-complete text field?
April 17, 2010, 10:56:03 am

seems like that is your best option

would be great if you can share your code after u've implemented it, and also blog about it

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Individual Prefix as an auto-complete text field?
April 17, 2010, 11:06:30 am
Yes, I'd be happy to.  Will post here when I have something to share.

Thanks,
Allen
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Individual Prefix as an auto-complete text field?
April 19, 2010, 08:35:56 pm
Well, this solution is working now.  There were a few unexpected twists and turns, but the result is just what the spec called for, and I think it's a reasonably sound -- though there's surely room for improvement. 

If you're interested you can see the code and an explanation of it in this blog post on my site:
http://www.TwoMiceAndAStrawberry.com/blog/46/civicrm-individual-prefix-field-as-auto-complete-text-input

Thanks, lobo, for your responses.

- Allen
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Individual Prefix as an auto-complete text field?

This forum was archived on 2017-11-26.