I have the following JavaScript code in a page:
var flagProceedWithSubmit;
function WarnDate() {
flagProceedWithSubmit = true;
$("#popUpDialog").dialog({
modal: true,
dialogClass: "no-close",
buttons: [{
text: "Sim",
click: function () {
alert("yes");
$(this).dialog("close");
// $("form").attr("action", '@Url.Action("SendOrdForm")');
$("form").submit(); // ***HERE***
return true;
}
}, {
text: "Não",
click: function () {
alert("no");
$(this).dialog("close");
return false;
}
}]
});
return (false); // flagProceedWithSubmit
}
// set event handler which checks the date for "high" values
$(document).ready(function () {
$("form").submit(function (e) {
flagProceedWithSubmit = true;
if ($("#tableRow").length == 0)
return true;
alert("this: " + $(this).value);
$(".appDatePickClass").each(function (index, item) {
if ((new Date(item.value) - (new Date()) > 2*30*24*3600*1000)) {
flagProceedWithSubmit = false;
}
});
if (!flagProceedWithSubmit)
flagProceedWithSubmit = WarnDate();
return (flagProceedWithSubmit);
}); // function not transposed to view Edit
});
When I submit the form with a date too high, a dialog appears, but when I press the button "Sim" ("Yes"), the form get submitted through the submit with date check, and not through the submit before the handler that I defined.
Could you help me?
Thank you.