ASP.NET MVC - How to prevent double click submit with jquery.validate.unobtrusive lib?

后端 未结 9 1117
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 07:47

I need to avoid the double click submitting behavior. I\'m using the client validation with the unobtrusive library. I have the following code for avoiding the double clic:<

9条回答
  •  伪装坚强ぢ
    2020-12-29 08:06

    Why not just use:

    function disableButtons() {
        var form = $(this);
        var btns = $("input:submit", form);
    
        if (!form.valid()) {
            // allow user to correct validation errors and re-submit
            btns.removeAttr("disabled");
        } else {
            btns.attr("disabled", "disabled");
        }
    }
    

    to disable your buttons and activate it using:

    $("form").bind("submit", disableButtons);
    

提交回复
热议问题