ajaxForm using Spry validation
I am trying to use spry validation with ajaxForm. The problem is I don't think my forcing spry validation at time of beforeSubmit is finding the form. I'm not getting any errors, seems like beforeSubmit isn't firing because it can't find the form, "form1"
$("#form1").ajaxForm({
url: "processPhoneEdit.php",
beforeSubmit: function(){
if (Spry) { // checks if Spry is used in your page
var r = Spry.Widget.Form.validate(form1); // validates the form
开发者_运维百科 if (r)
alert("testing");
return (r);
}
},
success: alert("success"),
complete: alert("complete")
});
I'm not much of a programmer, but this was my solution:
// Submit button is clicked
$("#submitShipment").click(function ()
{
// Spry validation: if true
if (Spry.Widget.Form.validate(form1) == true)
{
// opens the Please Wait dialog
$('#dialogPleaseWait').dialog('open');
// disables the submit button
$('#submitShipment').button('disable');
// Posts form to callback page, serializes the form into a URL string and waits for a result (success / fail)
$.get("callbacks/insertShipment.asp", $("#form1").serialize(), insertCallback);
}
else // Spry validation: if false
{
// opens jQuery UI dialog to inform user Validation failed
$('#dialogDespatchValFail').dialog('open');
}
});
Try this..
$("#form1").ajaxForm({
target:'#some_div',
url:'processPhoneEdit.php',
clearForm: 'true',
beforeSubmit: function(formData, jqForm, options){
if (Spry) { // checks if Spry is used in your page
r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
if (!r) {
return r;
}
}
if(r) {
$('#submit').attr({
'disabled':'disabled',
'value':'Processing. Please Wait...'
});
}
},
success: function() {
$('#form1').hide();
}
});
精彩评论