Subscribe to Child Entry Updates

Experimental Snippet 🧪

Code

Filename: gpnf-add-child-entries-to-the-top.js

/**
 * Gravity Perks // Nested Forms // Subscribe to Child Entry Updates
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Experimental Snippet 🧪
 */
// Get your Nested Forms JavaScript instance where "4" is the Nested Form field ID.
var gpnf = window.GPNestedForms_GFFORMID_13;
var entryCount = 0;
var doingItLive = false;

gpnf.viewModel.entries.subscribe( function( entries ) {
	if ( ! doingItLive ) {
		entryCount = entries.length;	
	}
}, null, 'beforeChange' );

gpnf.viewModel.entries.subscribe( function( entries ) {
	// Check if an entry was added.
	if ( ! doingItLive && entries.length > entryCount ) { 
		doingItLive = true;
		gpnf.viewModel.entries.splice( 0, 0, gpnf.viewModel.entries.pop() );
		entryCount = entries.length;
		doingItLive = false;
	}
} );

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.