I’ve attached the following js to an exposed views form field and it works on first page load but when the form is changed (by ajax) it doesn’t fire.
I can’t quite work out where to add an event listener for onchange of the select list.
The following doesn’t use jQuery but uses the core once library so I would like to avoid jQuery.
/** * @file * Landing page adjustments. */ (function (Drupal, once) { 'use strict'; /** * Attached behavior for Custom DataLayer. * * @type {{attach: Drupal.behaviors.CurrentSelectOption.attach}} */ Drupal.behaviors.CurrentSelectOption = { attach: function attach(context) { // First page load let elements = once('CurrentSelectOption', 'select#edit-field-event-country.form-select', context); elements.forEach(processingCallback); } }; function processingCallback(value, index) { let option = value.options[value.selectedIndex] value.remove (option); value.add (option, 0); } })(Drupal, once);