Problem/Motivation

When installed on a site using bootstrap theme the "other" field is always displayed. It should be displayed only when the "other" value is selected from the drop down.

Themes and modules can alter element markup by adding wrapper elements. This is valid for custom module development too.

Both select and input visible with nothing selected

<div class="form-item js-form-item form-type-select js-form-type-select form-item-field-favorite-color-0-select-other-list js-form-item-field-favorite-color-0-select-other-list form-group">
      <label for="edit-field-favorite-color-0-select-other-list" class="control-label">Favorite Color</label>  
  <div class="select-wrapper"><select class="form-text form-select form-select-other-list form-select form-control" data-drupal-selector="edit-field-favorite-color-0-select-other-list" id="edit-field-favorite-color-0-select-other-list" name="field_favorite_color[0][select_other_list]"><option value="_none" selected="selected">- None -</option><option value="red">Red</option><option value="green">Green</option><option value="blue">Blue</option><option value="other">Other</option></select></div>
  </div>

Proposed resolution

Figure out the input element based not on the immediate parent, but a specific selector instead.

var input_element = $(this).parent().next();

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ainsofs created an issue. See original summary.

mradcliffe’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
Issue summary: View changes
FileSize
4.5 KB

Thank you for reporting an issue, @ainsofs. It is much appreciated.

I think the most likely scenario is that there is a template preprocess or alter function that changes the behavior of either input or select elements. I took a spin on simplytest.me, and found this to be the case. There is an additional div.select-wrapper element. Currently the javascript in select other relies on core markup, but this probably should not be the case.

ainsofs’s picture

FYI I tested this with the experimental claro theme in 8.8.5 using simplytest and it has the same issue

mradcliffe’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.58 KB

Thank you for the additional testing. That really helped me be able to test locally.

I think we can change to use drupal-data-selector, which should be pretty standard. I haven't tested this with bootstrap theme yet, but I'll try to do so.

mradcliffe’s picture

Status: Needs review » Needs work

No, this approach isn't going to work. Bootstrap changes the data-drupal-selector to the select list and the extra wrapper elements are still going to break it.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
2.42 KB
2.23 KB

I think this should work using data-drupal-selector for both list and text input elements.

Also Drupal 8+ uses jQuery 3 so need to switch to using .on rather than .bind.

ainsofs’s picture

thanks #6 worked for me using 8.x-1.4, core 8.7.11 and bootstrap 8.x-3.15

  • mradcliffe committed be589ea on 8.x-1.x
    Issue #3126148 by mradcliffe, ainsofs: Fixes js to not depend on core...
mradcliffe’s picture

Status: Needs review » Fixed

Thank you for testing. I've committed this to 8.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.