Skip to content

Instantly share code, notes, and snippets.

@Ovis
Created March 27, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ovis/1f4a4120eb0e8d03ec65e7604ff14fe5 to your computer and use it in GitHub Desktop.
Save Ovis/1f4a4120eb0e8d03ec65e7604ff14fe5 to your computer and use it in GitHub Desktop.
jQuery Validation対応多重送信防止処理
var isSubmit = false;
//jQuery Validationの読み込み確認
if (typeof jQuery != "undefined" && typeof $.validator != "undefined") {
$.validator.unobtrusive.options = {
errorPlacement: function ($error, $element) {
if ($error.text().length === 0) {
return true;
} else {
isSubmit = false;
//送信ボタンを有効化(checkMultiplexSubmit関数のほうが先に呼ばれるため)
$(this).closest('form').find("[type='submit']").css('pointer-events', 'auto');
return false;
}
}
}
}
function checkMultiplexSubmit(form) {
if (!isSubmit) {
var elements = form.elements;
for (var i = 0; i < elements.length; i++) {
if (elements[i].type == 'submit') {
//送信ボタンを無効化
elements[i].style.pointerEvents = "none";
}
}
isSubmit = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment