Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions gp-nested-forms/gpnf-add-child-entries-to-the-top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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;
}
} );
Loading