bootstrap-validator
bootstrap-validator copied to clipboard
How to custom validate without adding required attribute to the field
Hi,
I would like to know how to custom validate without adding required attribute to the field. Because having <input data-equals="hello"/>
and
$('#myForm').validator({ custom: { equals: functions(el$){ ... } } })
does not work. but adding a required
to the field execute the custom validations. How to validate a field wich is not required?
I got this from documentation:
You can override this value from within your code if you need to change this default behavior. Alternatively, you can add
data-validate="true"
/data-validate="false"
to a specific input to force its inclusion / exclusion in the set of validated fields.
Ignoring custom validators for empty fields that are not required was deliberately added because someone considered a problem: https://github.com/1000hz/bootstrap-validator/issues/214
I also find it unfortunate.
Well, this is the second time within the past few months I ran into this problem. Could we perhaps come up with a way, to selectively force a validator to run on empty input fields too?
We could add a data attribute to the field, like data-force-validators="this, that"
.
Or just as data-validatorname=...
runs the validator only on non-empty, some other variation (e.g. data-validatorname-force=...
) would always run it.
Ok, I know this is sort of my pet peeve, but I think I've ran into this again, for the third time. I am trying to do complex validation based on different checkboxes and whenever I remove a checkbox the validator fails to run.
So now, I believe the default should be to validate optional fields too, and let developers switch this feature off, by providing some sort of data attribute. (Please see issue #334 as well.)