gpnf_should_delete (JS)

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Add confirmation to Delete buttons in the parent form
  5. Since

Description

Filter whether the child entry should be deleted. Useful for adding custom confirmations before deleting.

Usage

gform.addFilter( 'gpnf_should_delete', 'my_custom_function' );

Parameters

  • shouldDelete boolean

    Whether the child entry should be deleted. Defaults to true.

  • item object

    The child entry being deleted.

  • $trigger JQuery

    The element that triggered the deletion.

  • gpnf GPNestedForms

    Current instance of the GPNestedForms object.

Examples

Add confirmation to Delete buttons in the parent form

This snippet adds a confirmation to the Delete buttons in the parent form much like the confirmation when deleting from the Edit modal.

/**
 * Gravity Perks // Nested Forms // Require Confirmation to Delete Child Entry on Parent Form
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Require users to confirm delection of a child entry on the parent form. This works the same was as the
 * confirm-to-delete requirement in the child form.
 *
 * Instructions:
 *
 * 1. Install this snippet with our free Custom JavaScript plugin.
 *    https://gravitywiz.com/gravity-forms-code-chest/
 */
window.gform.addFilter( 'gpnf_should_delete', function( shouldDelete, items, $trigger, gpnf ) {
	if ( ! $trigger.is('.gpnf-row-actions .delete-button') ) {
		return shouldDelete;
	}
	if ( ! $trigger.data( 'isConfirming' ) ) {
		$trigger
			.data( 'isConfirming', true )
			.text( gpnf.modalArgs.labels.confirmAction );
		setTimeout( function() {
			$trigger
				.data( 'isConfirming', false )
				.text( gpnf.modalArgs.labels.delete );
		}, 3000 );

		return false;
	}
	return shouldDelete;
} );

Since

This filter is available since Gravity Forms Nested Forms 1.0-rc-1.10.