Delete Child Entries When Parent Value Changes

Instructions

  1. Install this snippet with our free Custom JavaScript plugin. https://gravitywiz.com/gravity-forms-code-chest/

  2. Configure the snippet for your form/fields based on the inline instructions.

Code

Filename: gpnf-delete-child-entries-when-parent-value-changes.js

/**
 * Gravity Perks // Nested Forms // Delete Child Entries When Parent Value Changes
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Instruction Video: https://www.loom.com/share/304641c3136049d0a8d1cf58c7041df5
 *
 * Instructions:
 *
 * 1. Install this snippet with our free Custom JavaScript plugin.
 *    https://gravitywiz.com/gravity-forms-code-chest/
 *
 * 2. Configure the snippet for your form/fields based on the inline instructions.
 */
// Update "4" to the ID of the field on the parent that when changed should delete the child entries.
$( '#input_GFFORMID_4' ).on( 'change', function() {
	// Update "5" to the ID of the Nested Form field on the parent form.
	var gpnfA = window.GPNestedForms_GFFORMID_5;
	gpnfA.viewModel.entries().forEach( function( item ) {
		var $deleteButton = $( 'tr[data-entryid=' + item.id + ']' ).find( '.delete-button' );
		gpnfA.deleteEntry( item, $deleteButton );
	} );
} );

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.