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.
When testing this module I noticed that the text field for `Other` was always visible. I would prefer if it were only to appear when someone selects 'Other' from the select list above it. I'm not sure if that is a bug in the existing javascript or what, but there is a tool for this in core already, so we could make use of #states here to save us some hassle.
// Setup text input.
$name = $field['field_name'] . '[' . $element['#language'] . '][' . $delta . '][select_other_list]';
$element['select_other_text_input'] = array(
'#type' => 'textfield',
'#title' => t('Provide other option'),
'#title_display' => 'invisible',
'#size' => 60,
'#attributes' => array(
'class' => array('form-text form-select-other-text-input'),
),
'#states' => array(
'visible' => array(
':input[name="' . $name . '"]' => array('value' => 'other'),
),
),
);
Comment | File | Size | Author |
---|---|---|---|
#5 | cck_select_other-2651572-views-js-fix-5.patch | 2.19 KB | mradcliffe |
| |||
#5 | cck-select-other-js-example.png | 46.4 KB | mradcliffe |
#5 | cck-select-other-views-js-not-working.png | 33.36 KB | mradcliffe |
#4 | cck_select_other-states-2651572-3.patch | 3.57 KB | jenlampton |
| |||
#2 | cck_select_other-states-2651572-1.patch | 3.22 KB | jenlampton |
Comments
Comment #2
jenlamptonpatch.
Comment #4
jenlamptoncopy/paste fail. trying again.
Comment #5
mradcliffeI was not able to reproduce the issue with the other text input always being displayed in a form. Is there a specific browser that it is not functional in?
I tried using #states back in 2010 when I began porting the module to Drupal 7, but I found a significant performance impact. This may not be the case in 2016 though the current JavaScript solution is pretty fast by itself.
The 7.x-2.x branch still had views refactoring to do, and the exposed filter WAS showing this issue. I was able to fix the exposed filter and a bug when configuring exposed filter though this branch still needs work.