Score:0

#limit_validation_errors not working for reset button?

in flag

I have a page view with some exposed filters (i.e. main content page). Some exposed filters are auto-complete fields (i.e. user references). So if I type some rubbish for user name and submit form I get error that user doesn't exist, which is correct. However if I press button "Reset" instead of emptying all the fields and really resetting the form it gets validated and I get error same as with submitting it? Why is that?

Anyway, I tried to solve this by adding in my hook_form_alter row like:

//  unset ($form['actions']['reset']);
$form['actions']['reset']['#limit_validation_errors'] = [];

So there really is $form['action']['reset'] (i.e. if I unset it Reset button disappears), but that form altering does nothing - validation still happens when I press reset button and instead emptying auto-complete field(s) I get validation error.

Any idea how to solve this?

Jaypan avatar
de flag
You have referred to a `submit` button and a `reset` button in your post, but only showed a bit of code relating to one of them.
in flag
My mistake, in code it's really 'reset', but I typed it wrong in text after. And that's the only code I added related to this issue.
in flag
If I change reset button type from "submit" to "button" it seems to work, at least for some view pages.
Jaypan avatar
de flag
Type `button` does not trigger validation or submission handlers, so that makes sense.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.