- 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
Eduardo Morales Alberti → made their first commit to this issue’s fork.
- 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
Same, here.
On the issue https://www.drupal.org/project/search_api/issues/2869121 → was removed the requirement for SearchApiFulltext.php// We use custom validation for "required", so don't want the Form API to // interfere. // @see ::validateExposed() $form['#required'] = FALSE;
Reading the original issue → , it was to avoid form errors when the input came empty because of the exposed filters when visiting the page for the first time.
When a visitor comes to the search page first, there will already be an error message and the filter will have a red border, since it has no value.
Instead of removing the requirement, I propose removing the required errors when the field is empty.
- @eduardo-morales-alberti opened merge request.
- Status changed to Needs review
over 2 years ago 6:17pm 23 March 2023 - Status changed to Active
over 2 years ago 8:12pm 25 March 2023 - 🇦🇹Austria drunken monkey Vienna, Austria
Thanks for the suggestion, but that’s definitely too much “magic” for a solution, and certain to break in lots of situations.
Also, please don’t use MRs in this module’s issue queue, since testing doesn’t work for them. (See #3190024: Problem with test dependencies when testing issue forks → .) - 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
This will not work, as @drunken monkey says, is too much magic. I will add custom validation to my field, and check if is empty.
At the moment I do know how to validate that the field is required because exposed filters do not work as the regular form does. - 🇬🇧United Kingdom joachim
I've hacked around this problem using a combination of the core patch from 🐛 Views exposed text filter set to required shows an empty error and form error on page load Needs work and restoring the #required = TRUE that SearchApiFulltext::exposedTranslate() removes.
But I've encountered another problem: if search_api_autocomplete module is present, it runs the search query in its autocomplete controller, which requires building the view, which requires building and submitting the exposed form. At which point, FormValidator rightly complains that there is no value for the #required fulltext filter element -- since at that point, the only query parameter in the current request is the 'q' for the autocomplete.