gpnf_init_nested_form

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Examples
    1. Populate the Parent Form ID

Description

Do something immediately before the nested form modal is initialized.

Usage

gform.addAction( 'gpnf_init_nested_form', 'myCustomFunction' );

Parameters

  • nestedFormId int

    The ID of the nested form being initialized in the modal.

  • gpnf \GPNestedForms

    The instance of GPNestedForms (specific to the parent form and Nested Form field) that is initializing the modal.

Since

This action is available since Gravity Forms Nested Forms 1.0-beta-8.25.

Examples

Populate the Parent Form ID

This example demonstrates how to populate the ID of the parent form that is loading the child form into a field on the child form. This is useful if you want to apply conditional to your child form based on the parent form from which the child form is being loaded.

/**
 * Gravity Perks // Nested Forms // Populate Parent Form ID in Child Form
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * This is useful if you want to apply conditional to your child form based on the parent form from which the child form is being loaded.
 *
 * 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.
 */
gform.addAction( 'gpnf_init_nested_form', function( childFormId, gpnf ) {

	// Update "123" to your the ID of your child form.
	var targetChildFormId  = 123;

	// Update "4" to the ID of the child field in which the parent form ID will be populated.
	var targetChildFieldId = 4;

	if ( childFormId == targetChildFormId ) {
		// Delaying setting value so Populate Anything can pick up the change event.
		// Internal: HS#32287.
		setTimeout( function() {
			$( '#input_' + targetChildFormId + '_' + targetChildFieldId ).val( gpnf.formId ).change();
		} );
	}
} );