Skip to content

gpnf-limit-entry-min-max-from-field.php: Fixed an issue with entry min max recalculation logic not working. #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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