This is a select element with an 'Other...' option which pops up a textfield where the user can type in a value directly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Heine’s picture

Status: Needs review » Needs work

An 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?)?

  $form = array();
  
  $options = array(
    'one' => t('First Option'),
    'two' => t('Second Option'),
  );
  
  $form['test'] = array(
    '#type' => 'comboselect',    
    '#title' => t('Example'),
    '#required' => TRUE,
    '#default_options' => $options,
    '#default_value' => 'two', // won't work, needs to be t('Second 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.

John Morahan’s picture

Status: Needs work » Needs review

The 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)

John Morahan’s picture

Status: Needs review » Needs work

Uhh, 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.

John Morahan’s picture

Status: Needs work » Needs review
FileSize
3.68 KB

Seems there have been some upload problems all round, today. Let's try this one again.

Dave Reid’s picture

Status: Needs review » Closed (won't fix)
Dave Reid’s picture

Version: 5.x-1.x-dev » 7.x-1.x-dev
Status: Closed (won't fix) » Postponed

Actually 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.

quicksketch’s picture

This 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.

danielb’s picture

Dave, please check back in the Select (or other) issue

joostvdl’s picture

Subscribe