简体   繁体   中英

Avoid submit form twice Parsley - Jquery

I'm trying to avoid submit form twice. Basically, I would like to disable the submit button after the first click and if the form is validated.

I'm using Parsley , and this is what I tried to do:

<script type="text/javascript">
    window.Parsley.on('parsley:form:validated', function(e){
        if (e.validationResult) {
            alert("OK");
            $('input[type=submit]').attr('disabled', 'disabled');
        }else{
            alert("KO");
        }
    });
</script>

But it seems like it never called. The alert never appears.

What am I doing wrong?

Please, note that I added that script inside the layout that every page with a form extend. So because of that I didn't use the id directly.

I solved in this way:

<script type="text/javascript">
    $(function () {
        $('form').parsley().on('form:validated', function(e) {
            if (e.validationResult) {
                $('input[type=submit]').attr('disabled', 'disabled');
            }
        });
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM