Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a select element with an 'Other...' option which pops up a textfield where the user can type in a value directly.
Comment | File | Size | Author |
---|---|---|---|
#4 | elements-comboselect.patch | 3.68 KB | John Morahan |
elements-comboselect.patch | 3.41 KB | John Morahan | |
Comments
Comment #1
Heine CreditAttribution: Heine commentedAn excellent, feature rich addition to the elements module.
I've only one issue with the current element. Submitting the form below with the 'Second Option' selected will get me 'Second Option' as form value in the submit handler.
Should it not return the _key_ of the option, similar to the way #type select behaves or, when 'Other' has been selected, the value of the texfield?
The same holds for the behaviour of #default_value; shouldn't it accept keys (but then again, what to do when key is the value of the other option?)?
To use the element in its current inception, you'd have to pass the #default_options array as #type value to the submit handler so it can reconstruct the key selected . One also has to choose the right translated value for #default_value in the builder.
Comment #2
John Morahan CreditAttribution: John Morahan commentedThe trouble is that it's a combination of two elements, one of which naturally returns a key, the other naturally returns a value.
How about something like this? The value is now e.g. array('option' => 'two', 'value' => 'Second option') and the #default_value would be array('option' => 'two') for the select, or array('value' => t('Third option')) for the textfield.
This gives the developer a way to tell the difference between a selected option and a typed value that's identical to an existing key or value.
(I haven't had time to test this version extensively yet)
Comment #3
John Morahan CreditAttribution: John Morahan commentedUhh, there was supposed to be a patch attached to that, but I guess it didn't upload and now I'm in the office and the patch is at home... I'll upload it this evening.
Comment #4
John Morahan CreditAttribution: John Morahan commentedSeems there have been some upload problems all round, today. Let's try this one again.
Comment #5
Dave ReidYou want this module: http://drupal.org/project/select_or_other
Comment #6
Dave ReidActually I've posted in #981530: Port Select (or other) module to D7 to see if the module would like to merge into Elements since I think it would make a lot of sense.
Comment #7
quicksketchThis would be great if Elements and Select or Other merged, then Webform could use all of the fields provided by elements, right now we're only supporting Select or Other, since it's the most important one for us.
Comment #8
danielb CreditAttribution: danielb commentedDave, please check back in the Select (or other) issue
Comment #9
joostvdl CreditAttribution: joostvdl commentedSubscribe