Skip to content

fix: enforce min/max validation on NUMBER fields and add maxLength support #12516

Open
sheikhlimon wants to merge 1 commit intoopencrvs:developfrom
sheikhlimon:ocrvs-10959
Open

fix: enforce min/max validation on NUMBER fields and add maxLength support #12516
sheikhlimon wants to merge 1 commit intoopencrvs:developfrom
sheikhlimon:ocrvs-10959

Conversation

@sheikhlimon
Copy link
Copy Markdown

@sheikhlimon sheikhlimon commented May 4, 2026

Description

NUMBER fields had min/max in their config but they weren't being forwarded to the HTML input or enforced by Zod validation. Country configs had to work around this with custom isBetween validators.

This forwards min, max, and maxLength as HTML attributes to the Number input and generates Zod .min()/.max() constraints from the field config so validation enforces the range automatically.

Closes #10959

Checklist

  • I have linked the correct Github issue under "Development"
  • I have tested the changes locally, and written appropriate tests
  • I have tested beyond the happy path (e.g. edge cases, failure paths)
  • I have updated the changelog with this change (if applicable)
  • I have updated the GitHub issue status accordingly

@sheikhlimon
Copy link
Copy Markdown
Author

quick heads up on two things I noticed while working on this:

  • maxLength on <input type="number"> gets ignored by browsers – followed the same pattern TEXT fields use in the codebase (HTML attribute only, no JS enforcement). curious if this should be handled differently or if that's fine for now?

  • if a country config already has isBetween validators, the new Zod constraints would run alongside them and could produce duplicate errors for overlapping ranges. Farajaland's child.weightAtBirth has min: 0 in config AND isBetween(0, 6) as a custom validator – entering-1 would trigger both. should country configs remove their isBetween workarounds after this lands, or should we skip Zod constraints when custom validators exist?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NUMBER field min/max doesnt work & maxLength would be a necessary config value

1 participant