Skip to content

Disable validation for elements out of current form #198

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

Closed
burdiuz opened this issue Jan 6, 2015 · 3 comments
Closed

Disable validation for elements out of current form #198

burdiuz opened this issue Jan 6, 2015 · 3 comments

Comments

@burdiuz
Copy link

burdiuz commented Jan 6, 2015

Hi!
I have 2 form settings for Canada and US addresses, they are identical except of State/Province enumeration. Both forms are connected to same model object. When user switches country, specific form is shown. When I launch validation with default country, it works fine. But if I select another country, so new settings loaded and new form elements added -- it breaks validation because somehow validation goes through all form fields(CA and US have different enumerations for their states/provinces, so value will be invalid for one of them), for both countries even if they its not visible and should not be validated at all. This is confusing because selected country fiends show all fields valid but in total validation fails and "invalid" fields are being nullified with validator.
For now I found 2 solutions

  1. make own validation cycle asking each field is it valid
  2. change validation event handler in a way that will prevent inactive form fields to be validated.
@burdiuz
Copy link
Author

burdiuz commented Jan 6, 2015

It seems I've found easy to use solution described in this ticket:
#200

@davidlgj
Copy link
Contributor

davidlgj commented Jan 7, 2015

Marking it as a duplicate of #200

@fiddur
Copy link

fiddur commented Jan 7, 2015

I don't know if proper oneOf-support is implemented for the form yet, but with regards to json-schema and tv4 (the validator) a oneOf-statement in the address could be used, stating that it either should be country "Canada" and matching a certain province, or country "USA"... In either case, the validator shouldn't require a field to be set if it isn't marked as "required" in the schema.

@davidlgj davidlgj closed this as completed Jan 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants