gpnf_init_script_args

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Change Modal Title and Submit Button
  5. Since

Description

Filter the arguments that will be used to initialized the nested forms frontend script.

Usage

Apply to all forms and fields.

add_filter( 'gpnf_init_script_args', 'my_custom_function' );

Apply to all fields for a specific form.

add_filter( 'gpnf_init_script_args_FORMID', 'my_custom_function' );

Apply to a specific form and field.

add_filter( 'gpnf_init_script_args_FORMID_FIELDID', 'my_custom_function' );

Parameters

  • args array

    • formId int

      The current form ID.

    • fieldId int

      The field ID of the Nested Form field.

    • nestedFormId int

      The form ID of the nested form.

    • displayFields array

      The fields which will be displayed in the Nested Forms entries view.

    • entries array

      An array of modified entries, including only their display values.

    • ajaxUrl string

      The URL to which AJAX requests will be posted.

    • modalLabels array

      The following properties are passed in the $modalLabels array.

      • title string

        The title to be displayed in the modal header.

      • editTitle string

        The title to be displayed in the modal header when editing an existing entry.

      • submit string

        The text to be displayed inside Submit button.

      • editSubmit string

        The text to be displayed inside Submit button when editing an entry.

      • cancel string

        The text to be displayed inside Cancel button.

      • delete string

        The text to be displayed inside Delete button.

      • confirmAction string

        The question to be displayed when confirming an action.

    • modalColors array

      The following properties are passed in the $modalColors array.

      • primary string

        A HEX color that will be set as the default background color of the Add and Edit Entry buttons.

      • secondary string

        A HEX color that will be set as the default background color for Cancel button.

      • danger string

        A HEX color that will be set as the default background color for Delete and Are you sure? buttons.

    • modalHeaderColor string

      A HEX color that will be set as the default background color of the modal header.

    • modalClass string

      The class that will be attached to the modal for styling.

    • modalStickyFooter boolean

      Whether the footer should stick to the bottom of the modal.

    • enableFocusTrap boolean

      Whether the nested form should use a focus trap when open to prevent tabbing outside the nested form.

  • field GF_Field

    The current Nested Form field.

  • form array

    The current form.

Examples

Change Modal Title and Submit Button

By default, the submit button label will be the same as the modal title, “Add {Item}” and “Edit {Item}” respectively. Use this snippet to change the title and submit button labels for both the Add and Edit modals.

<?php
/**
 * Gravity Perks // Nested Forms // Change Modal Title and Submit Button
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 */
// Update "123" to your form ID and "4" to your Nested Form field ID.
add_filter( 'gpnf_init_script_args_123_4', function( $args ) {
	$args['modalLabels']['title']      = 'Create New Child Entry';
	$args['modalLabels']['editTitle']  = 'Edit Child Entry';
	$args['modalLabels']['submit']     = 'Submit';
	$args['modalLabels']['editSubmit'] = 'Edit';
	return $args;
} );

By default, the Nested Forms field modal has “sticky” footer. It will keep the footer visible on longer forms by sticking it to the bottom of the screen. Use this snippet to “unstick” the footer and it will appear at the bottom of the form.

<?php
/**
 * Gravity Perks // Nested Forms // Unstick the Modal Footer
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 */
add_filter( 'gpnf_init_script_args', function( $args ) {
	$args['modalStickyFooter'] = false;
	return $args;
} );

Since

This filter is available since Gravity Forms Nested Forms 1.0.