-
Notifications
You must be signed in to change notification settings - Fork 92
gpnf-limit-entry-min-max-from-field.php: Fixed an issue with the snippet not working correctly on form load.
#1066
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
Conversation
…ippet not working correctly on form load.
WalkthroughThis change updates the logic within the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller (output_script)
participant F as EntryLimitFunction
C->>F: Call output_script() with max field input
F->>F: Parse the input to a numeric value
F->>F: Check using isNaN(value)
alt Parsed value is not a number
F->>C: Return Infinity
else Parsed value is a valid number
F->>F: Check if value is truthy
alt Value is truthy
F->>C: Return parsed value
else
F->>C: Return self.defaultMax
end
end
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
| var value = parseInt($maxField.val()); | ||
|
|
||
| return value ? value : self.defaultMax; | ||
| return isNaN(value) ? Infinity : (value || self.defaultMax); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic improvement to prevent premature "maximum number reached" message.
The change correctly addresses the issue by checking if the parsed value is not a number (NaN) and returning Infinity in that case. This prevents the system from incorrectly defaulting to a maximum of 0 when the max field is empty, allowing users to add entries without encountering the premature "maximum number reached" message.
This fix resolves the critical issue described in the PR where users couldn't add child entries because the system was incorrectly displaying the maximum limit message when the form loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2897379455/81715
Summary
When using the Dynamically Set Entry Min/Max From Field Value snippet, the Nested Form shows "maximum number reached" before any child entry is even added.
The key issue was default-ing to a zero max value.