bootstrap-validator icon indicating copy to clipboard operation
bootstrap-validator copied to clipboard

How to custom validate without adding required attribute to the field

Open Guervyl opened this issue 6 years ago • 4 comments

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?

Guervyl avatar Sep 05 '18 16:09 Guervyl

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.

heyhusen avatar Dec 07 '18 03:12 heyhusen

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.

andreaskundig avatar Feb 08 '19 10:02 andreaskundig

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.

fancsali avatar Oct 04 '19 11:10 fancsali

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.)

fancsali avatar Oct 09 '19 15:10 fancsali