Reputation: 14142
I am using the jQuery validate plugin for doing 'live' form validation. I am trying to not show the error messages that appear as it affects the layout etc..
It generates a label that messes up my styling on the page, is it possible to have this not display at all?
// the label it generates for an error
<label for="address_1" class="error">Please enter at least 2 characters.</label>
$('#checkout-form').validate({
rules: {
first_name: {
minlength: 2,
required: true
},
last_name: {
minlength: 2,
required: true
}
},
highlight: function (element) {
$(element).addClass('#error')
.closest('.form-group').removeClass('valid');
},
success: function (element) {
element.addClass('valid')
.closest('.form-group').removeClass('error');
}
});
// custom css
<style type="text/css">
label.valid {
position: relative;
top: -25px;
right: 10px;
float: right;
width: 16px;
height: 16px;
background: url('/assets/images/icons/tick.png') center center no-repeat;
display: inline-block;
text-indent: -9999px;
}
label.nonvalid {
position: relative;
top: -25px;
right: 10px;
float: right;
width: 16px;
height: 16px;
background: url('/assets/images/icons/cross.png') center center no-repeat;
display: inline-block;
text-indent: -9999px;
}
Upvotes: 0
Views: 3275
Reputation: 337560
You need to set the showErrors
parameter to contain your own logic to show messages as you need them:
$('#checkout-form').validate({
showErrors: function(errorMap, errorList) {
// do something with the errors
},
// rest of your code...
});
Upvotes: 1
Reputation: 40639
You can use errorPlacement
like,
$('#checkout-form').validate({
errorClass:'error_border',
rules: {
first_name: {
minlength: 2,
required: true
},
last_name: {
minlength: 2,
required: true
}
},
errorPlacement: function(error, element){
/* Need to add this function to remove the error default placement */
}
});
Read Error handling in jQuery Validation Plugin
Upvotes: 1