Skip to content
Merged
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
13 changes: 11 additions & 2 deletions gp-nested-forms/gpnf-limit-entry-min-max-from-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,18 @@ public function output_script() {
});

gform.addAction( 'gform_input_change', function( el, formId, fieldId ) {
// Force Knockout to recalculate the max when the number has changed
if ( el.id === maxFieldId ) {
// Force Knockout to recalculate the max when the number has changed
window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ].viewModel.entries.valueHasMutated();
const gpnfViewModel = window[ 'GPNestedForms_{0}_{1}'.gformFormat( self.parentFormId, self.nestedFormFieldId ) ]?.viewModel;

// Use the standard Knockout method if available.
if ( typeof gpnfViewModel?.entries?.valueHasMutated === 'function' ) {
gpnfViewModel.entries.valueHasMutated();
// Fallback for scenarios where 'entries' is a computed observable (no valueHasMutated).
// Trigger reactivity by reassigning a shallow copy of the observable array.
} else if ( typeof gpnfViewModel?.entriesRaw === 'function' ) {
gpnfViewModel.entriesRaw( gpnfViewModel.entriesRaw()?.slice() );
}
}
} );

Expand Down
Loading