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) »
  • Custom data input field types
Pages: [1]

Author Topic: Custom data input field types  (Read 943 times)

tklawsuc

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.06
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.2/5.3
Custom data input field types
July 15, 2011, 09:53:10 am
We need a select list with an option for "other" which will then display a textbox to allow the user to enter a value. I know I can create two fields for this and then hook into buildForm, customize the tpl, and also use jquery to link the two together but I would rather have it as a data type since I need to have several fields like this. So in short I am asking if/how we can create a custom input field type...not field. e.g. create another option in the data field type for say Alphanumeric that is called "Select plus Other".

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: Custom data input field types
July 15, 2011, 02:01:50 pm

This is potentially a not-so-small change. A few thoughts:

1. Might want to do it for checkbox / radio also (since the are similar to select)

2. I think it would be easiest to store the "other" value entererd in a seperate DB column (varchar?) Can be a lot more free-form and the user has more flexibility. This means:

* Choosing the "+other" option triggers 2 columns being created in the custom value table
* The display basically checks the two columns and displays the non-empty one

The above changes affect a fair part of the code base. If you'd like to work on this, ping us on IRC and we can get you started

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

davesage

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 3
  • CiviCRM version: 3.4 & 4.1
  • CMS version: Joomla 1.5 & 2.5
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Custom data input field types
July 15, 2011, 03:17:22 pm
Sorry to jump onto this thread - not sure if this is related or another use case.

Would it be an idea to have a normal free text field that you can type anything into but also has an options list defined and if you type the beginning of anything in the options list then it shows an auto-complete select for it (a bit like the current lookups for employer etc..) This ould be ajax and if you select the option it just pops the text in the field, if you chose not to select the option then it just saves the text into the field.

This would mean only one field in the dbase but would allow for peopel to quickly select the text in the options list for common options, while still giving free text entry for the rest.

Sorry if I've gone off topic or I've misunderstood your requirement.

If this is already possible (which I'm sure it is using hooks I suspect) could someone shed some light on this as I'd like to have the option to use it in the future.

Cheers,

Dave

tklawsuc

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.06
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.2/5.3
Re: Custom data input field types
July 18, 2011, 07:51:51 am
lobo - my thought was that if we can use one column we could then have application logic that if the db value is not in the defined list of options then it will display in a textbox as "other". I will need to familiarize myself with extending civi a bit more before I can commit to adding this feature. Can you point me in the right direction to add another input field type?

Dave - I was considering using an auto-complete but we don't want the options list to be populated with these "other" entries that people enter. Plus we want them to try and select something from the available options before resorting to  typing their own. Using auto-complete you miss out on seeing all the options since you are getting a list of options based on what you started typing. Thanks for the suggestion though!

Tom

davesage

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 3
  • CiviCRM version: 3.4 & 4.1
  • CMS version: Joomla 1.5 & 2.5
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Custom data input field types
July 18, 2011, 11:07:14 am
Very true, seeing all the options first is a good point stops people thinking it isn't in the list when it is but with a different term.

Humm, I'll be interested to see how you do this in that case.

Cheers,

Dave

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: Custom data input field types
July 18, 2011, 11:36:13 am

You'll need to follow the code at CRM/Custom/* and CRM/Core/BAO/Custom*

You might want to use the IRC channel and ask folks questions as you encounter them

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

tklawsuc

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.06
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.2/5.3
Re: Custom data input field types
July 21, 2011, 12:29:42 pm
Thanks lobo...I'll post my final solution here if I don't just decide to use a dropdown and "other" textbox.

Tom

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom data input field types

This forum was archived on 2017-11-26.