Parsley documentation states the following about data-parsley-group
Assign a group to a field for specific group validation. eg: data-parsley-group="signup". This way, you could only validate a portion of a form and not all the fields. Can be multiple. eg: data-parsley-group='["foo", "bar"]'
One could think that you could use data-parsley-group
to validate only a portion of the form and, after validation, the form would submit. This is not correct.
data-parsley-group
is intended to be used in multi-step forms, where the entire form must be validated, and validation is applied to one or few groups at a time. The form is submitted once all groups are validated.
What you need is:
- If company is not checked: Validate only the first fields and ignore company fields.
- If company is checked: Validate all form fields.
So, the form is the same but sometimes the form has more fields. I suggest you would use disabled to address the issue. When company is checked, show the fields, otherwise hide the fields and make them disabled.
When binding parsley to the form, add the :disabled
to the excluded
option so Parsley can ignore this fields.
I have updated the JSFiddle to meet your needs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…