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'),
      ),
    ),
  );
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jenlampton created an issue. See original summary.

jenlampton’s picture

Status: Active » Needs review
FileSize
3.22 KB

patch.

Status: Needs review » Needs work

The last submitted patch, 2: cck_select_other-states-2651572-1.patch, failed testing.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
3.57 KB

copy/paste fail. trying again.

mradcliffe’s picture

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

Working for multiple value and single value field configuration

Views exposed filter not working