Fixing multi-submission differently

Take into account dynamic forms
Client validation
This commit is contained in:
Sebastien Ros 2016-04-15 13:03:47 -07:00
parent ac3a0387fa
commit 8ebf58d27d
4 changed files with 98 additions and 82 deletions

View File

@ -8,7 +8,7 @@
Layout.Title = T("New {0}", Html.Raw(typeDisplayName)).Text;
}
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", new { ReturnUrl = Request.QueryString["ReturnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", new { ReturnUrl = Request.QueryString["ReturnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data", @class = "no-multisubmit" })) {
@Html.ValidationSummary()
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
@Display(Model)

View File

@ -8,7 +8,7 @@
Layout.Title = pageTitle;
}
@using (Html.BeginFormAntiForgeryPost(Url.Action("Edit"), FormMethod.Post, new { enctype = "multipart/form-data" })) {
@using (Html.BeginFormAntiForgeryPost(Url.Action("Edit"), FormMethod.Post, new { enctype = "multipart/form-data", @class= "no-multisubmit" })) {
@Html.ValidationSummary()
// Model is a Shape, calling Display() so that it is rendered using the most specific template for its Shape type
@Display(Model)

View File

@ -81,14 +81,30 @@
$("input[type=checkbox]:not(:disabled)").prop('checked', $(this).prop("checked"))
});
//Prevent double-click on buttons of type "submit"
$("form button[type='submit'], form input[type='submit']").click(function (e) {
var form = $(this).closest("form")[0];
if (typeof(form.formSubmitted) != "undefined") {
//Prevent multi submissions on forms
$("body").on("submit", "form.no-multisubmit", function (e) {
var submittingClass = "submitting";
form = $(this);
if (form.hasClass(submittingClass)) {
e.preventDefault();
return;
}
form.formSubmitted = true;
form.addClass(submittingClass);
buttons = form.find("[type='submit']");
buttons.prop("disabled", true)
// safety-nest in case the form didn't refresh the page
setTimeout(function () {
form.removeClass(submittingClass);
buttons.prop("disabled", false)
}, 5000);
e.preventDefault();
return;
});
// Handle keypress events in bulk action fieldsets that are part of a single form.