- Issue created by @diegopino
When delivering/updating Exposed Forms for views, Drupal.behaviors.autosubmitExcludeTextfield fails to set again the 'data-bef-auto-submit-exclude' if present.
If the a Views exposed form is refreshed/updated via Ajax the once() code in will fail.
Because Drupal (as of 10.4) still does not provide this functionality as part of core, testing this patch (or a similar approach) might help
https://www.drupal.org/files/issues/2025-02-26/drupal-exposed_forms_in_b... β
The reason for that is because the once() runs over a context that has as a child the '.bef-exposed-form', but ignores if the the actual context has that class, which is what happens with an Ajax driven reload of an exposed form is executed, the context == form.
There are two ways of approaching this:
This one requires that the returned form (context) has actually changed its #id (which is not the case for the demo patch shared), but even so, it will not fail (will (once) twice, the wrapper and the child
**
* Adds the data-bef-auto-submit-exclude to elements with type="text".
*/
Drupal.behaviors.autosubmitExcludeTextfield = {
attach: function (context, settings) {
if (!settings.better_exposed_filters?.autosubmit_exclude_textfield) {
return;
}
let elementsToAttach = [];
if (context !== document && context.classList.contains('bef-exposed-form')) {
elementsToAttach = once('autosubmit-exclude-textfield', context);
}
else {
elementsToAttach = once('autosubmit-exclude-textfield', '.bef-exposed-form', context);
}
$(elementsToAttach).each(function () {
$(this).find('*[type="text"]').attr('data-bef-auto-submit-exclude', '');
});
}
};
This other option is even simpler. If what changed is the actual Form, then `onceing` it really makes no sense, just setting the value is enough.
**
* Adds the data-bef-auto-submit-exclude to elements with type="text".
*/
Drupal.behaviors.autosubmitExcludeTextfield = {
attach: function (context, settings) {
if (!settings.better_exposed_filters?.autosubmit_exclude_textfield) {
return;
}
let elementsToAttach = [];
if (context !== document && context.classList.contains('bef-exposed-form')) {
elementsToAttach = context;
}
else {
elementsToAttach = once('autosubmit-exclude-textfield', '.bef-exposed-form', context);
}
$(elementsToAttach).each(function () {
$(this).find('*[type="text"]').attr('data-bef-auto-submit-exclude', '');
});
}
};
What none of this code really does is to allow mixed cases to exist: One Exposed form with and another one without text field exclusion, one a first page load, this code will unify their settings. It takes settings.better_exposed_filters?.autosubmit_exclude_textfield as global, which means on a first load (context === document) either all/or non text fields inside a .bef-exposed-form will get this data attribute.
Which is unclear to me why, if there are already values for the other options
```
data-bef-auto-submit-full-form = ""
data-bef-auto-submit = ""
data-bef-auto-submit-delay = {int} 500
data-bef-auto-submit-minimum-length = {int} 3
```
there is no `data-bef-auto-submit-exclude` set at the Render array level instead?
Wait for the maintainers to confirm which of the 2 approaches is better
None
None
None
Thanks a lot
Active
7.0
Code