Pristine
Pristine copied to clipboard
How to Ignore hidden elements
I have dependent fields in the form. How to ignore hidden fields from validation.
Hidden fields are ignored by default. Are you seeing a different behavior?
Yes, Depentdent fields not ignored. Check this fiddle. https://jsfiddle.net/Dhruvang/pvnheqy2/4/
When you select Yes in first question, second question will be hide. But it is not ignored.
@dhruvangg, only input type=hidden
fields are ignored. It does not look for hidden elements (I'm not sure if it should at this moment). But there's one way to solve the issue in your case: remove the required
attribute from the dependant attribute and re-initialize the Pristine object. In any case, you have to re-initialize the Pristine object if any attribute is modified.
Hi, can you add some function for re-initialize for example reset()
@1ucay, you can basically do the following to re-initialize:
pristine.reset(); // resets errors
pristine.destroy(); // clean up
pristine = new Pristine(form); // re-init
If you have dependent/dynamic fields in a form, than try using combo of hidden
attribute with disabled
. Than, you can pass something like this
const pristine = new Pristine(form)
const activeInputs = (form) => [...form.elements].filter(input => !input.disabled && input.type !== "hidden"))
pristine.validate(activeInputs(form))