I have two elements(dropdowns) which are very closely placed. These elements are required fields.
I am using jquery valiate to validate the fields. The error message are showing for both the elements and the space between the elements increases as the error message of first control is displayed near the element
$('#RegisterForm').validate({
rules: {
Country:{required: true},
State:{required: true}
},
messages: {
Country:{required: "Select Country"},
State:{required: "Select State"}
}
});
I have tried using break before the elements as:
$('#RegisterForm').validate({
rules: {
Country:{required: true},
State:{required: true}
},
messages: {
Country:{required: "<br/>Select Country"},
State:{required: "<br/>Select State"}
}
});
When i did so, the second element moves to next line.
How can i show the error messages just below the elements without affecting the alignment/placement of nearby elements.
Java script ready(function() { $("#basic-form"). validate(); }); This is based on the assumption that you have already added the required JavaScript files. Adding those lines of JavaScript will make sure that your form is properly validated and shows all the error messages.
Definition of jQuery validate errorplacement. The jQuery validate errorplacement() function is used to customize the placement of an error message. This function is a built-in function in jQuery. These function changes the default behavior of the validation plugin to insert the error label after the input fields.
remove(); $(". error"). removeClass("error"); It will be ok, when you need to validate it again.
valid()Returns: Boolean Description: Checks whether the selected form is valid or whether all selected elements are valid.
Use the errorPlacement option (see documentation here: http://docs.jquery.com/Plugins/Validation/validate#toptions)
$('#RegisterForm').validate({
rules: {
Country:{required: true},
State:{required: true}
},
messages: {
Country:{required: "Select Country"},
State:{required: "Select State"}
},
errorPlacement: function(error, element) {
error.appendTo( element.parent("td").next("td") );
}
});
Of course you'll have to adapt the code to your situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With