Trigger Population on Button Click

Instead of automatically populating fields when an input is changed, trigger the population when a button is clicked.

Instructions

  1. Add snippet to form using https://gravitywiz.com/gravity-forms-code-chest/
  2. Customize inputButton and optionally buttonSelector to match your form the desired field
  3. Add HTML field to your form and add the following code to the HTML field:

Code

Filename: gppa-trigger-population-on-button-click.js

/**
 * Gravity Perks // GP Populate Anything // Trigger Population on Button Click
 *
 * Instead of automatically populating fields when an input is changed, trigger the population when a button is clicked.
 *
 * Instructions:
 *  1. Add snippet to form using https://gravitywiz.com/gravity-forms-code-chest/
 *  2. Customize inputButton and optionally buttonSelector to match your form the desired field
 *  3. Add HTML field to your form and add the following code to the HTML field:
 *      <button class="trigger-gppa">Click Me</button>
 */
var inputSelector = '#input_FORMID_FIELDID';
var buttonSelector = '.trigger-gppa';

function disableListener() {
    $(inputSelector).data('gppaDisableListener', true);
}

disableListener();

$(document).on('gppa_updated_batch_fields', function( event, formId, fieldIds ) {
    disableListener();
});

$('#gform_GFFORMID').on('click', buttonSelector, function(event) {
    // Prevent submission of form when this button is clicked
    event.preventDefault();

    $(inputSelector)
        .data('gppaDisableListener', false)
        .trigger('forceReload');
});

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.