How to use identifier or class instead of using name in bootstrap validator

My goal is a validated field (s) that has a class name or identifier using the bootstrap validator

Here is a sample code:

HTML:

<input id="myFirstId" class="myClass" type="text" name="myFirstName" /> <input id="mySecondId" class="myClass" type="text" name="myLastName" /> 

JS:

  $('#myForm').bootstrapValidator({ fields : { myFirstName : { validators : { notEmpty : { message : 'required' } } }, myLastName : { validators : { notEmpty : { message : 'required' } } } } }); 

but I want one block to check these two elements using the bootstrap validator

ex.

 $('#myForm').bootstrapValidator({ fields : { myClass : { // <-- this is not working but i want to validate those // object with has 'myClass' class. validators : { notEmpty : { message : 'required' } } } } }); 
+5
source share
1 answer

See http://bootstrapvalidator.com/settings/#field-selector

You can use selector instead of a name to use the class name:

 $('#myForm').bootstrapValidator({ fields: { myClass: { selector: '.myClass', validators: { notEmpty: { message: 'required' } } }, } }); 
+6
source

Source: https://habr.com/ru/post/1206705/


All Articles