Skip to content

BUG: pre-submit custom form validation not applied to radiobuttons and checkboxes #2676

@ehenighan

Description

@ehenighan

Found while testing a slightly niche use-case in a questionnaire form I'm building - when you apply custom validation across a form using the HTML5 hooks to enforce that the user has to fill out at least one of a set of answers on a page (i.e. no particular radiogroup is required, but at least one of the visible radiogroups must have a value), the onsubmit validation isn't respected.

This is because the 'shouldInclude' function excludes unticked checkboxes/radiobuttons but the 'validateElement' check is inside the 'shouldInclude' block.

It's easy to fix and I've tested locally - just separated out 'couldInclude' and 'shouldValidate' from 'shouldInclude' in order to lift up the validation outside the 'shouldInclude' block, but wasn't sure where you'd want a PR targeting now there's version 2 and 1.9.12 on the go at the same time.

Will check back shortly to add code examples!

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions