Skip to content

Show min/max messages for number fields on blur - #3730

Open
vivi-the-going-merry[bot] wants to merge 5 commits into
masterfrom
fix/issue-7014-number-range-validation
Open

vivi-the-going-merry[bot] wants to merge 5 commits into
masterfrom
fix/issue-7014-number-range-validation

Conversation

@vivi-the-going-merry

@vivi-the-going-merry vivi-the-going-merry Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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-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).
Before (master) After
before after

🤖 Generated with Claude Code

vivi-the-going-merry Bot and others added 2 commits November 23, 2026 06:13
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.

Fixes Strategy11/formidable-pro#7014

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@deepsource-io

deepsource-io Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

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.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Nov 25, 2026 4:27p.m. Review ↗
JavaScript Nov 25, 2026 4:27p.m. Review ↗

Important

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.

querySelectorAll: selector => selector === 'input,select,textarea' ? [ field ] : []
};
function jQuery() {
return { ready() {}, hasClass: () => true, querySelectorAll: () => [] };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

}
const context = {
window: {},
document: { body: { classList: { contains: () => false } }, dispatchEvent() {} },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread tests/js/numberRangeValidation.test.mjs Outdated
window: {},
document: { body: { classList: { contains: () => false } }, dispatchEvent() {} },
jQuery,
CustomEvent: function() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread tests/js/numberRangeValidation.test.mjs Outdated
window: {},
document: { body: { classList: { contains: () => false } }, dispatchEvent() {} },
jQuery,
CustomEvent: function() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

} );

test( 'A number within range has no error', () => {
assert.equal( getNumberErrors( '10', {}, attrs ), undefined );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
window: {},
document: { body: { classList: { contains: () => false } }, dispatchEvent() {} },
jQuery,
CustomEvent() {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@Crabcyborg Crabcyborg added this to the 7.2 milestone Nov 23, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 23, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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".

Before (master JS), 5000 on blur: before

After (PR JS), 5000 on blur: after

Tests run at bf3f239 (CI skipped all of these):

  • 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):

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

@franky-the-going-merry franky-the-going-merry Bot added vivi-pickup and removed franky-review franky-working Franky is actively reviewing this labels Nov 23, 2026
@vivi-the-going-merry vivi-the-going-merry Bot added vivi-working Vivi is actively working this and removed vivi-pickup labels Nov 23, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vivi-the-going-merry vivi-the-going-merry Bot added franky-review and removed vivi-working Vivi is actively working this labels Nov 23, 2026
@vivi-the-going-merry

Copy link
Copy Markdown
Contributor Author

Method: in-place push
Pushed to: #3730 (branch fix/issue-7014-number-range-validation, unchanged PR number)

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.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 23, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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):

  1. 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.
  2. 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.
  3. The step mismatch from min vs 0, and the novalidate decision, from the PR description.
  4. 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.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 23, 2026
@garretlaxton

Copy link
Copy Markdown

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.

@vivi-the-going-merry vivi-the-going-merry Bot added vivi-working Vivi is actively working this and removed vivi-pickup labels Nov 25, 2026
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>
@vivi-the-going-merry vivi-the-going-merry Bot added franky-review run tests and removed vivi-working Vivi is actively working this labels Nov 25, 2026
@vivi-the-going-merry

Copy link
Copy Markdown
Contributor Author

Method: in-place push
Pushed to: #3730 (branch fix/issue-7014-number-range-validation, unchanged PR number)

Reply to garretlaxton's 11-24 comment, fixed in 9a3c5cd:

  1. 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.
  2. 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().

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ 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.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3730      +/-   ##
============================================
+ Coverage     43.29%   43.74%   +0.44%     
+ Complexity    14178    14177       -1     
============================================
  Files           237      237              
  Lines         47725    47730       +5     
============================================
+ Hits          20662    20878     +216     
+ Misses        27063    26852     -211     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 25, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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:

after submit

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):

  1. 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.
  2. 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).
  3. FrmProFieldNumber::validate() repeats the range strings instead of using the Lite helpers (private), so wording can drift between Pro and the JS message.
  4. The step vs min mismatch and novalidate decisions in the PR description.
  5. 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.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 25, 2026
@Crabcyborg

Copy link
Copy Markdown
Contributor

@garretlaxton Vivi has pushed some updates. Can you try again?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants