Search code examples
jqueryvalidationjquery-validation-engine

How to fix bug errorPlacement in jquery validation plugin


I'm using plugin jQuery validation to handle invalid fields. So, I set defaults validator like this:

$.validator.setDefaults({
    errorElement: 'span',
    errorClass: 'help-block text-danger',
    errorPlacement: function(error, element) {
        error.prepend("<i class='fa fa-warning'></i> ");
        error.appendTo($(element).parent());
    },
    highlight: function(element) {
        $(element).closest('.form-group').addClass('has-error');
    },
    unhighlight: function(element) {
        $(element).closest('.form-group').removeClass('has-error');
    },
    onfocusout: function(element,event){
        $(element).valid();
    }
});

I added the tag (i) with class (fa fa-warning) errorPlacement

PB : The Tag element does not appear in second focus in field. You can see this in this example https://jsfiddle.net/MokhtarSF/btt17gg9/3/


Solution

  • Problem Solved

    I added showErrors function in validator defaults for handle message error content instead of errorPlacement.

    I will keep this link as reference.

    `https://jsfiddle.net/MokhtarSF/btt17gg9/3/`
    

    Thanks