Droide
Droide

Reputation: 1859

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.

Upvotes: 1

Views: 640

Answers (1)

Droide
Droide

Reputation: 1859

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>

Upvotes: 2

Related Questions