[jQuery] validate and form plugins
i have a table with an edit button in each row. when the edit button is
clicked, the following script is run:
//edit click
$('#edit_lnk_' + index).click(function() {
Boxy.get('#cancel_changes_lnk').show();
$('#ddlProjects').clearSelect();
$('#ddlTasks').clearSelect();
populateBoxy(index);
});
function populateBoxy(index) {
SetupFormValidationRules();
//...more code
}
function SetupFormValidationRules() {
$('#add_edit_form').validate({
errorPlacement: function(error, element) {
error.appendTo(element.next());
},
rules: {
tbxHours: {
required: true,
//number: true,
min: .25
},
ddlProjects: {
required: function(element) {
return $('#ddlProjects')[0].selectedIndex == 0;
}
}
},
messages: {
tbxHours: {
required: "<br/>Hour field is required.",
//number: "Hour field must be a number.",
min: "<br/>Hour field must be a value greater than or equal
to 15 min (.25)"
},
ddlProjects: {
required: "<br/>You must select a project"
}
},
submitHandler: function(form) {
var options = {
url: '/Time/SaveTimeActivity',
type: 'POST',
contentType: "application/x-www-form-urlencoded",
success: function(result, status) {
Boxy.get('#cancel_changes_lnk').hide();
GetDay(_tabIndex);
},
resetForm: true,
error: function(xhr, status, thrownError) {
if (xhr.getResponseHeader("SafeErrorMessage")) {
SetStatusMessage("Error");
alert(xhr.getResponseHeader("SafeErrorMessage"));
}
else {
SetStatusMessage("Unknown error occurred");
alert("Unknown Error: Please contact technical
support");
}
document.body.style.cursor = 'default';
}
}
$(form).ajaxSubmit(options);
return false;
}
}).resetForm();
}
the first time the form [#add_edit_form] is submitted, the ajax submit works
great and everything is great(the modal hides, grid repopulated with new
data, etc). then, when i click any other edit button on the grid, the modal
reappears with all the correct data, but when i hit submit, a default submit
occurs (no ajaxSubmit)
any help would be appreciated! thanks
--
View this message in context: http://www.nabble.com/validate-and-form-plugins-tp21503313s27240p21503313.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.