Search code examples
javascriptjquerywordpressgravityforms

jQuery Function Does Not Fire if Gravity Form Entry Fails


I am using jQuery to add a "disabled" attribute to my submit button once it is clicked.

        $('#submit-button').click(function () {
            setTimeout(function () {
                $('#submit-button').attr('disabled', 'disabled')
            }, 50);
        })

I am using gravity forms and am using AJAX to produce a spinner image when it's clicked, that's why I have the setTimeout function.

This works the first time the submit button is clicked. If the entry passes validation then it's no problem, the disabled attribute is loaded and then goes to the confirmation page.

The issue is when the validation fails, the page refreshes and shows the errors (e.g. this was not filled out correctly) and then click the submit button does not fire the jQuery click function to add the disabled attribute


Solution

  • Gravity forms gform_page_loaded works - https://docs.gravityforms.com/gform_page_loaded/

    I put the code in a function and used

    jQuery(document).on('gform_page_loaded', function(event, form_id, current_page){
            myFunction()
        });
    

    So now the function runs after the AJAX call