Help on Jquery Validation Plugin

0

I have the following HTML code which shows me a text box:

 <div class="form-group empresa_rfc">
                                <label for="empresa_rfc" class="col-sm-2 control-label"><p class="text-left">RFC: (*)</p></label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="empresa_rfc" name="empresa_rfc" placeholder="RFC" >
                                </div>
                            </div>

I am using Bootrap 3.3.7. And then I have this validation with the Jquery Validate Plugin from link

$("#form_empresa").validate({
            focusCleanup: true,
            rules: {
                empresa_rfc: { required: true }
            },
            invalidHandler: function(event, validator){
                var errors = validator.numberOfInvalids();
                if (errors){
                    var message = errors == 1
                        ? 'You missed 1 field. It has been highlighted'
                        : 'You missed ' + errors + ' fields. They have been highlighted';
                    swal({
                        title:"Error:",
                        text: message,
                        type: "error",
                        allowOutsideClick: false,
                        confirmButtonColor: '#d33',
                        confirmButtonText: "Corregir"
                    });
                    //console.log(message);
                }
            }
        });

The previous code shows me and indicates the field that has not been completed, and shows me a alert indicating the errors contained in 'message'. My question is, how can I affect the

<div class="form-group empresa_rfc">

and add the 'has-error' class of Bootstrap so you can point that field in specific? Specifically, it should look like this:

<div class="form-group empresa_rfc has-error">
    
asked by Weyler A. 17.06.2017 в 07:48
source

1 answer

0

You can add the attribute messages:{} of the plugin, leaving something like this:

rules: {
  RFC: {
    required: true
  }
},
messages: {
  RFC: {
    required: ""
  }
}

That will make the input that is incorrect or missing value, but will add a small space below the input that is the value of the message . . p>     

answered by 19.06.2017 в 16:55