jquery tools validation re-bind after loading different content
I'm using the jquery tools validation plugin for client side form validation. i have one javascript file which loads the function below on ready.
What i'm doing is, i load a form, when this is being validated successfully and submitted, i load another form, and would like the function below to handle any form thats being loaded within the if (json.success && json.next) statement block.
For some reason, when the second form is loaded, the validator is not being re-bound to the class (.signup_form) of the new form, and the validation does not occur.
any idea how i could attach a $.live or anything to this, so it'll automatically rebind itself to whatever form gets loaded with the .signup_form class after success?
/* For clarifica开发者_Python百科tion: json.next is the url of the next form to load */
$(".signup_form").validator({
position: 'top left',
offset: [-12, 0],
message: '<div><em/></div>' // em element is the arrow
}).submit(function(e) {
var form = $(this);
// client-side validation OK.
if(!e.isDefaultPrevented()) {
// submit with AJAX
$.post(form.attr('action'), form.serialize(), function(json) {
// everything is ok. (server returned true)
if (json.success && json.next) {
form.parent().parent().load(json.next); // Slide here
form.reset();
// server-side validation failed. use invalidate() to show errors
} else {
form.data("validator").invalidate(json);
}
}, "json");
// prevent default form submission logic
e.preventDefault();
}
});
any help is greatly appreciated. T
Okay, i figured it out... geez its so obvious.
so all of the code above i have within a
form_listener = function() {}
block.
now all i need do do is to call the form listener after i load the new form:
.
.
// everything is ok. (server returned true)
if (json.success && json.next) {
form.parent().parent().load(json.next, function(){
form_listener();
});
.
.
sweet.
精彩评论