Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple field selectors to separately add rules to the same field #151

Open
TheCognito opened this issue Sep 8, 2024 · 0 comments

Comments

@TheCognito
Copy link

Is your feature request related to a problem? Please describe.
Limitations of the current addField functionality results in an inconsistent validation experience when the provided selector matches fields that may have existing rules applied already. It will validate when "forced" (e.g. upon form submission), but does not detect both rules when the field is "touched".

For example, I might register addField('input[min]', ...) and addField('input[max]', ...) separately (as part of a library of generalized rules), but currently, the system applies validation only to the first matching rule, rather than allowing all relevant validation rules to be applied. This limitation forces me to handcraft hyper-specific logic for individual forms and their fields instead of constructing generic, reusable validation rules that may overlap.

Describe the solution you'd like
I would like the validation logic to be extended so that when a form input matches multiple registered fields or "rules," all relevant validation rules are applied. This would allow addField to behave more like addRule, enabling fields that match multiple rules (e.g., an input that supports both min and max constraints) to be validated against all the rules they match, rather than stopping at the first match. I've opened PR #150 with code that I believe resolves the issue (sorry if opening the PR jumped the gun on approving this idea!)

Describe alternatives you've considered
An alternative would be to build custom, handcrafted validation logic for each form, but this approach sacrifices reusability and modularity. Another option could be registering composite rules (e.g., input[min][max]), but this still requires anticipating every combination of constraints, making it less scalable.

Additional context
While the max/min example is perhaps a bit trivial, you can imagine the potential if I were building out a more comprehensive form wrapper for my projects that may include several rules that may or may not overlap in various scenarios, or more dynamically constructed forms with CMS control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant