Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ID or CLASS instead of using name in Bootstrap Validator

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

Here is the example 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 a single block to validated those two element using 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'
                    }
                }
            }
        }
 });
like image 505
Andoy Abarquez Avatar asked Nov 12 '14 09:11

Andoy Abarquez


1 Answers

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

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

$('#myForm').bootstrapValidator({
    fields: {
        myClass: {
            selector: '.myClass',
            validators: {
                notEmpty: {
                    message: 'required'
                }
            }
        },
    }
});
like image 153
artm Avatar answered Sep 19 '22 22:09

artm