You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Show min/max messages for number fields on blur - #3730
Broken: A Number field's min/max wasn't part of Formidable's JS validation. On blur a value outside the range got no inline message and aria-invalid stayed false. Submit showed the generic "Enter a number".
Changed:
FrmFieldNumber now outputs data-minmsg / data-maxmsg with the same strings the server uses (shared helpers, so they can't drift).
checkNumberField() adds an error from those messages when validity.rangeUnderflow / rangeOverflow is set, falling back to data-invmsg if absent. validateField() (blur) and the submit path both pick it up, so aria-invalid and aria-describedby are set by the existing error code.
Not changed (decisions for review):
Step (stepMismatch) is left out. The browser counts steps from min, check_value_is_valid_with_step() counts from 0, so with min 5 / step 2 they disagree (6 vs 7). Needs a decision on which rule wins before JS can mirror it.
novalidate on JS-validated forms is left out: it changes current reportValidity() behaviour.
Verified:
node --test tests/js/numberRangeValidation.test.mjs: 2 of 4 fail on master JS, 4/4 pass with the fix.
PHPUnit test_add_extra_html_atts_includes_range_messages added; php -l clean. Not run locally.
Live (Lite only, Playground, form with Number min 5 / max 1000, JS validation on), blur after typing 1: on master, aria-invalid="false", no message. On this branch, aria-invalid="true", aria-describedby="frm_error_field_amt7014", message "Please select a higher number". 5000 shows "Please select a lower number". The env's frm.min.js is a stale copy, so I replaced it with the unminified formidable.js for the run.
Not tested: formidable.min.js is not rebuilt here (recent JS fixes don't touch it; frm.min.js is gitignored).
Number fields only failed JS validation for non-numeric input, so a value
outside min/max got no inline error or aria-invalid until the server check.
Pass the server's range messages as data attributes and use them when the
field's validity reports rangeUnderflow/rangeOverflow.
FixesStrategy11/formidable-pro#7014
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
We reviewed changes in 7f27c41...9a3c5cd on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
The reason will be displayed to describe this comment to others. Learn more.
Unexpected empty method 'ready'
Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.
The reason will be displayed to describe this comment to others. Learn more.
Unexpected empty method 'dispatchEvent'
Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.
The reason will be displayed to describe this comment to others. Learn more.
Expected method shorthand
ECMAScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.
The reason will be displayed to describe this comment to others. Learn more.
Unexpected empty method 'CustomEvent'
Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant `undefined` from function call
When an argument is omitted from a function call, it will default to undefined. It is therefore redundant to explicitly pass an undefined literal as the last argument.
The reason will be displayed to describe this comment to others. Learn more.
Unexpected empty method 'CustomEvent'
Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.
The reason will be displayed to describe this comment to others. Learn more.
Approve with non-blocking notes at bf3f239. I reproduced the bug and the fix in a real browser, and ran the tests CI skipped.
Live (Lite only, Chromium, form with Number min 5 / max 1000, JS validation on). The PR's FrmFieldNumber.php rendered the new attributes: data-minmsg="Please select a higher number", data-maxmsg="Please select a lower number", next to min="5" max="1000". The preview env serves a stale gitignored frm.min.js bundle, so for both runs I put the JS under test in its place: master js/formidable.js for before, the PR's for after.
Blur after typing
master JS
PR JS
1
aria-invalid="false", no message
aria-invalid="true", aria-describedby="frm_error_field_amt37302", "Please select a higher number"
5000
aria-invalid="false", no message
aria-invalid="true", "Please select a lower number"
10
no error
no error
Submitting 2 with the PR JS shows "Please select a higher number" inline, aria-invalid="true".
node --test tests/js/numberRangeValidation.test.mjs -> 4/4 pass. With master's js/formidable.js swapped in: 2 pass, 2 fail (the min and max cases), so the tests do catch the bug.
PHPUnit (wordpress-develop harness, PHP 8.5, Lite 035fc2c base): test_FrmFieldNumber 3 tests / 15 assertions OK; test_FrmFieldType 17 and test_FrmFieldValidate 15 OK. Deleting the data-minmsg line from add_extra_html_atts() fails the new test, so it is not hollow.
Notes (not blocking):
Not run: Pro active. The preview env's Pro (2026-11-06) would not activate against current Lite, so I read the source instead. FrmProFieldNumber extends FrmFieldNumber and calls the inherited add_extra_html_atts(), so the new attributes carry over. Currency-formatted Pro number fields render as type="text", which checkNumberField() never sees, so they are unaffected. Worth one look in a real Lite + Pro site before release.
FrmProFieldNumber::validate() repeats the two message strings as bare __() calls instead of using the new helpers. The helpers are private in Lite, so Pro cannot call them. If someone changes the wording in Lite, the Pro server message and the JS message drift apart. Not for this PR; a note for whoever next touches the strings.
js/formidable.min.js is tracked and this PR does not rebuild it, so the fix only reaches users after the next minified build (history shows it is rebuilt in release-prep commits). Fine if that is the convention here, just confirming it is intended.
The two decisions in the description (step mismatch from min vs 0, and novalidate) are still open. Both are out of scope here as stated.
CI: DeepSource JavaScript is red and I cannot read its details either. PHPStan, PHPCS, ESLint and the JS unit job were skipped for this bot-authored PR; none of those linters were run by me.
Note 3: fix commits on master (e.g. cea2411, b6bca1d) rebuild formidable.min.js, so a6ca0f2 does the same for checkNumberField. The 4 JS tests pass against the min file (2 fail on the old one).
Notes 1, 2, 4: no change here. Pro-active check, Pro message dedup and the step/novalidate decisions stay with the reviewers.
The reason will be displayed to describe this comment to others. Learn more.
Approve at a6ca0f2. Re-review of the whole PR; the only change since my last review (bf3f239) is the js/formidable.min.js rebuild, which closes my earlier note 3.
What I checked on the new commit
Diffing the rebuilt js/formidable.min.js against master's, word by word, shows changes only inside checkNumberField: the data-minmsg / data-maxmsg branch, the messageType logic and the data-invmsg fallback. Nothing else in the bundle moved.
I ran the PR's JS test against the minified file (a temp copy of tests/js/numberRangeValidation.test.mjs pointed at js/formidable.min.js): 4/4 pass. The checked-in test reads js/formidable.js, so this covers the min file separately.
js/formidable.js, the PHP, the PHPUnit test and the ESLint config are byte-identical to bf3f239. Nothing else is different.
Tests run: node --test tests/js/numberRangeValidation.test.mjs at a6ca0f2 → 4/4 pass (also 4/4 against the min file). PHPUnit test_FrmFieldNumber was not re-run at a6ca0f2: no PHP or PHPUnit file changed since I ran it at bf3f239 (3 tests / 15 assertions OK).
Visual check: not exercised at this head. No rendering was re-run; the before/after screenshots are in my review at bf3f239 and used js/formidable.js, not the min file. The min-file check above is a logic test only.
Still open from my earlier notes, for the human reviewers rather than Vivi (Vivi confirmed she is leaving these to the reviewers):
Pro-active check not run (the preview env's Pro would not activate against current Lite). Source read says FrmProFieldNumber inherits the new attributes. Worth one look on a real Lite + Pro site before release.
FrmProFieldNumber::validate() repeats the two message strings instead of using the new Lite helpers (they are private), so the Pro server message and the JS message can drift apart if Lite's wording changes.
The step mismatch from min vs 0, and the novalidate decision, from the PR description.
DeepSource JavaScript is still red and I cannot read its details. PHPStan, PHPCS and the JS unit job were skipped for this bot-authored PR, and I did not run those linters.
No action is needed from Vivi, so I am not handing this back to her.
Custom "Invalid format" message is no longer shown for range errors. On submit, a value below min on a field with a custom invalid message now shows "Please select a higher number" instead of the custom text. The range messages aren't customizable. I inferred the old behavior from the issue and didn't run master.
A number input with no data-minmsg and no (or blank) data-invmsg gets aria-invalid="true" with no message.
A number field with a custom invalid message no longer outputs the default
range messages, so JS validation shows the custom text for a value outside
min/max, as before.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reply to garretlaxton's 11-24 comment, fixed in 9a3c5cd:
Custom invalid message on submit: right, fixed. On master a value below min on submit reached checkValidity(), which uses data-invmsg, so the custom text showed. FrmFieldNumber now outputs data-minmsg/data-maxmsg only when the field's invalid message is empty or the default ("Enter a number"). A custom message means no range attributes, so JS falls back to data-invmsg as before. Cost: a field whose stored invalid message differs from the default (custom, older default, other locale) gets no new inline range message. Say if you'd rather the range message win.
No messages at all: not from this PR. With no data-invmsg, checkValidity() (js/formidable.js:265) already sets an empty error for any invalid field, range included, on master. Lite now always outputs the range messages on the default path, so this case only remains for a field with a custom or blank invalid message, which is the master behaviour. Left alone.
Tests: PHPUnit test_add_extra_html_atts_skips_range_messages_for_custom_invalid_message added, php -l clean, not run locally; run tests label added so CI runs it. JS tests unchanged (4/4 at a6ca0f2). I did not run master in a browser: point 1 is from reading checkValidity() and FrmFieldNumber::validate().
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.74%. Comparing base (48786ec) to head (9a3c5cd). ⚠️ Report is 19 commits behind head on master.
The reason will be displayed to describe this comment to others. Learn more.
Approve at 9a3c5cd. Re-review of the whole PR. Since my approval at a6ca0f2 the only change is Vivi's fix for Garret's 11-24 report (custom invalid message lost on submit): FrmFieldNumber::add_extra_html_atts() now writes data-minmsg / data-maxmsg only when the field's invalid message is empty or the default ("Enter a number"). The JS, the minified bundle and the JS tests are unchanged from a6ca0f2.
Live, Lite only at 9a3c5cd, JS validation on, three Number fields (min 5, max 1000) that differ only by stored invalid message:
Field (stored invalid message)
Rendered attributes
Value 1 on blur
Submit with 3 / 5000
A: "Enter a number" (default)
data-minmsg, data-maxmsg present
aria-invalid="true", "Please select a higher number"
same range message
B: "Numbers only please" (custom)
no range attributes
aria-invalid="true", "Numbers only please"
"Numbers only please"
C: "[field_name] is invalid" (old default)
no range attributes
aria-invalid="true", "C old default is invalid"
same
Garret's case (B on submit) now shows the custom text, as it did on master, and B/C also get an error on blur instead of the silent aria-invalid="false" from the original bug. Screenshot after submit with 3 / 3 / 5000:
Not exercised: I did not run master for the custom-message case (Garret's report and Vivi's reply both describe master's submit behavior; the table above is the PR's behavior).
Tests run at 9a3c5cd: PHPUnit test_FrmFieldNumber in the wordpress-develop harness → 4 tests / 18 assertions OK. CI also passed its PHPUnit legs (PHP 7.4, 8.0, 8.2 and 8.4 on WP trunk), and Vivi added the run tests label for that. Mutations of uses_default_invalid_message(): always true fails the new test; dropping the default-message comparison fails the new test; dropping the empty-string comparison fails test_add_extra_html_atts_includes_range_messages. The JS tests did not change and were not re-run (my a6ca0f2 run, 4/4 against both formidable.js and the min file, still applies; no JS file changed since).
Open items for the human reviewers (none block this PR, none need Vivi):
Product decision, from Vivi's reply: a field whose stored invalid message is not exactly the current default (custom, an older default such as C above, another locale) gets no inline range message, only its own invalid message. That is correct for custom text but means existing forms with an older stored default do not get the new range wording. Decide whether that is acceptable or whether the range message should win.
Pro-active check still not run on a real Lite + Pro site (source read says FrmProFieldNumber inherits the attributes, so it follows the same default-message rule).
FrmProFieldNumber::validate() repeats the range strings instead of using the Lite helpers (private), so wording can drift between Pro and the JS message.
The step vs min mismatch and novalidate decisions in the PR description.
DeepSource JavaScript is red and I cannot read its details; PHPStan, PHPCS, ESLint and the JS unit job were skipped for this bot-authored PR and I did not run them. The code-review / security-review skills were not run this tick.
@garretlaxton Vivi has pushed some updates. Can you try again?
Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Strategy11/formidable-pro#7014
Broken: A Number field's min/max wasn't part of Formidable's JS validation. On blur a value outside the range got no inline message and
aria-invalidstayedfalse. Submit showed the generic "Enter a number".Changed:
FrmFieldNumbernow outputsdata-minmsg/data-maxmsgwith the same strings the server uses (shared helpers, so they can't drift).checkNumberField()adds an error from those messages whenvalidity.rangeUnderflow/rangeOverflowis set, falling back todata-invmsgif absent.validateField()(blur) and the submit path both pick it up, soaria-invalidandaria-describedbyare set by the existing error code.Not changed (decisions for review):
stepMismatch) is left out. The browser counts steps frommin,check_value_is_valid_with_step()counts from 0, so with min 5 / step 2 they disagree (6 vs 7). Needs a decision on which rule wins before JS can mirror it.novalidateon JS-validated forms is left out: it changes currentreportValidity()behaviour.Verified:
node --test tests/js/numberRangeValidation.test.mjs: 2 of 4 fail onmasterJS, 4/4 pass with the fix.test_add_extra_html_atts_includes_range_messagesadded;php -lclean. Not run locally.1: onmaster,aria-invalid="false", no message. On this branch,aria-invalid="true",aria-describedby="frm_error_field_amt7014", message "Please select a higher number".5000shows "Please select a lower number". The env'sfrm.min.jsis a stale copy, so I replaced it with the unminifiedformidable.jsfor the run.formidable.min.jsis not rebuilt here (recent JS fixes don't touch it;frm.min.jsis gitignored).master)🤖 Generated with Claude Code