I've a registration form validated with jquery.validate plugin.
Now, if the form its not valid, i want to put the result of validate in a bootstrap popover, but really, i don't have idea how i can do this.
Some help?
I've a registration form validated with jquery.validate plugin.
Now, if the form its not valid, i want to put the result of validate in a bootstrap popover, but really, i don't have idea how i can do this.
Some help?
The jQuery.validate plugin has a method called errorPlacement
.
This takes 2 arguments:
The Validator sends the error/valid message here and you can handle all the placement logic in there. What I tend to do is put all that in .setDefaults
before initialising the validator.
Example:
jQuery.validator.setDefaults({
ignore: "",
errorPlacement: function (error, element){
// Insert error messgae placement logic here
}
});
For showing and hiding tooltips for your errors, you'd need to use the errorPlacement
and success
callback functions.
Since you've shown no code of your own, here is a similar setup using the Tooltipster plugin, just to give you an idea about how to use these callback functions. Adjust as needed for Bootstrap popovers or whatever other tooltip plugin you may use.
$(document).ready(function () {
$('#myform').validate({
// rules and options here,
errorPlacement: function (error, element) {
// construct tooltip with message as per plugin method
$(element).tooltipster('update', $(error).text());
// show tooltip as per plugin method
$(element).tooltipster('show');
},
success: function (label, element) {
// hide tooltip as per plugin method
$(element).tooltipster('hide');
}
});
});
DEMO: http://jsfiddle.net/kyK4G/
Reference: https://stackoverflow.com/a/14741689/594235
Documentation: http://jqueryvalidation.org/validate
Checkout this: https://github.com/mingliangfeng/jquery.validate.bootstrap.popover
it is a plugin integrating jQuery validate and bootstrap popover, you may get some idea there.