Skip to content

Commit b05d037

Browse files
authored
gpnf-add-child-entries-to-the-top.js: Migrated from experimental folder.
1 parent 56e6249 commit b05d037

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Gravity Perks // Nested Forms // Subscribe to Child Entry Updates
3+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
4+
*
5+
* Experimental Snippet 🧪
6+
*/
7+
// Get your Nested Forms JavaScript instance where "4" is the Nested Form field ID.
8+
var gpnf = window.GPNestedForms_GFFORMID_13;
9+
var entryCount = 0;
10+
var doingItLive = false;
11+
12+
gpnf.viewModel.entries.subscribe( function( entries ) {
13+
if ( ! doingItLive ) {
14+
entryCount = entries.length;
15+
}
16+
}, null, 'beforeChange' );
17+
18+
gpnf.viewModel.entries.subscribe( function( entries ) {
19+
// Check if an entry was added.
20+
if ( ! doingItLive && entries.length > entryCount ) {
21+
doingItLive = true;
22+
gpnf.viewModel.entries.splice( 0, 0, gpnf.viewModel.entries.pop() );
23+
entryCount = entries.length;
24+
doingItLive = false;
25+
}
26+
} );

0 commit comments

Comments
 (0)