gppa_updated_batch_fields

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Listen for updates on a specific field.
    2. Select All Populated Checkboxes
    3. Auto-submit after fields are populated via QR code scan.

Description

An event that gets triggered when Populate Anything has dynamically updated a field’s choices or value.

Usage

$( document ).on( 'gppa_updated_batch_fields', function() { 
    // Do your magic!
} );

Parameters

  • event Event

    The JavaScript event for the gppa_updated_batch_fields request.

  • formId int

    The ID of the form for which the fields were updated.

  • updatedFieldIds array

    An array of IDs for fields that were updated.

  • triggerInputId array

    An array of IDs for fields that triggered the update.

  • instance GPPopulateAnything

    The current instance of GPPopulateAnything.

Examples

Listen for updates on a specific field.

/**
 * Gravity Perks // Populate Anything // Listen for Populate Anything Updates on a Specific Field
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 */
$( document ).on( 'gppa_updated_batch_fields', function( e, formId, updatedFieldIDs ) {
	var targetFieldId = 3;
	if ( parseInt( formId ) === GFFORMID && $.inArray( String( targetFieldId ), updatedFieldIDs ) !== -1 ) {
		console.log( 'Target field updated!' );
	}
} );

Select All Populated Checkboxes

/**
 * Gravity Perks // GP Populate Anything // Automatically Check Checkboxes
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything
 *
 * Instructions:
 *     1. Install our free Custom Javascript for Gravity Forms plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 *.    3. This snippet is meant to be a starting point. You will need to update the selectors accordingly
 */

// Select all choices for field ID 1 on initial load
jQuery('#button_1_select_all').each(function() {
	gformToggleCheckboxes(this);
});

// Select all choices for field ID 2 whenever its choices are repopulated dynamically
jQuery(document).on('gppa_updated_batch_fields', function(event, formId, fieldIds) {
	if (formId != GFFORMID) {
		return;
	}

	jQuery('#button_2_select_all').each(function() {
		gformToggleCheckboxes(this);
	});
})

Auto-submit after fields are populated via QR code scan.

Use GP QR Code to scan a QR code and Populate Anything to dynamically populate data based on the scanned QR code. Then, with this snippet, you can wait for Populate Anything to finish updating the fields and automatically submit the form.

/**
 * Gravity Perks // GP QR Code // Automatically Submit After Successful Scan (w/ Populate Anything)
 * https://gravitywiz.com/documentation/gravity-forms-qr-code/
 *
 * You want to auto-submit the form after you've scanned a QR code but you're using Populate Anything
 * to populate other fields based on the value scanned. You need to wait for Populate Anything to
 * finish fetching and populating that data before the form can be submitted. This snippet handles
 * that logic for you.
 *
 * We recommend installing this snippet with our free Custom Javascript plugin:
 * https://gravitywiz.com/gravity-forms-code-chest/
 */
gform.addAction( 'gpqr_on_scan_success', function( decodedText, decodedResult, gpqrObj ) {
	$( document ).off( 'gppa_updated_batch_fields.gpqr' );
	$( document ).on( 'gppa_updated_batch_fields.gpqr', function( event, formId ) {
		if ( gpqrObj.formId == formId ) {
			setTimeout( function() {
				$( '#gform_{0}'.gformFormat( formId ) ).submit();
			} );
		}
	} );
} );