Created
March 27, 2020 15:54
-
-
Save Ovis/1f4a4120eb0e8d03ec65e7604ff14fe5 to your computer and use it in GitHub Desktop.
jQuery Validation対応多重送信防止処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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