MPDX-9766 - Enforce error deferment until fields are touched in useAutosave#1851
Conversation
|
Preview branch generated at https://defer-errors.d3dytjb8adxkk5.amplifyapp.com |
Bundle sizes [mpdx-react]Compared against 9075fd9 No significant changes found |
zweatshirt
left a comment
There was a problem hiding this comment.
🤖 Multi-Agent Code Review — Verdict: ✅ CLEAN
Risk: 6/10 (MEDIUM) · standard mode · agents across the review: Architecture, Testing, Standards, Data Integrity, UX, Financial + dependency analysis
No blockers, no Important findings — only two sub-5 suggestions (inline). The feature is sound and independently verified.
What this PR does
Adds an opt-in deferErrorsUntilTouched flag to the shared useAutoSave hook (default false), enabled in the questionnaire wrapper so validation errors stay hidden until a field is touched — avoiding a wall of errors on arrival. Every questionnaire field is also marked required (asterisk + aria-required) so mandatory-ness stays visible even while errors are deferred.
Verified safe
- Validity gating preserved (Data Integrity, High confidence): error display is deferred, but
markValid/markInvalidis unchanged and independent oftouched— a user cannot Continue past hidden-but-invalid fields. Only the visual error is gated. - Backward compatible (dependency analysis):
useAutoSavehas 5 consumers; only the questionnaire wrapper opts in. With the flag defaultingfalse, the 4 other forms (PdsGoalCalculator, SalaryCalculator, GoalCalculator ×2) are byte-identical in behavior.showErrorreduces exactly to the original condition when the flag is off. - Accessibility (UX, High confidence):
aria-requiredis valid onrole=radiogroupand necessary (MUI'sFormControl requireddoes not propagate it to the group). Therequiredwork resolves the earlier concern that deferring errors left untouched required fields with no programmatic signal. - Standards: clean pass — named exports, localization, no
any, no unused imports, MUIsxconventions.
Suggestions (severity < 5 — informational, non-blocking)
See inline comments. In brief: (1) the two MinistryDetails selects have required but no explicit test assertion; (2) minor display caveats of the touched-state flag. Neither blocks merge.
| <Stack spacing={4}> | ||
| <TextField | ||
| select | ||
| required |
There was a problem hiding this comment.
| schema: yup.Schema; | ||
| disabled?: boolean; | ||
| saveOnChange?: boolean; | ||
| deferErrorsUntilTouched?: boolean; |
There was a problem hiding this comment.
There was a problem hiding this comment.
AI Review Auto-Approval
Risk Level: MEDIUM (6/10)
Verdict: CLEAN (no issues found)
This PR was auto-approved because:
- The multi-agent AI review determined it is medium risk
- No blocking issues were found
If you believe this PR needs human review, dismiss this approval and request a review manually.
canac
left a comment
There was a problem hiding this comment.
A couple minor thoughts, but thanks for noticing this issue and improving it!
| label={question} | ||
| helperText={error ? errorText : helperText} | ||
| error={error} | ||
| required |
There was a problem hiding this comment.
question: Are all number fields required? Like debt?
There was a problem hiding this comment.
I assumed if they are displayed to the user, then yes, unless we would prefer to populate empty field values with 0 even if displayed? I tend to lean toward required in general because it makes the user think through each question rather than rush through forms, but I can change this if we'd like. Maybe it's to refer to follow the original Google Form?
There was a problem hiding this comment.
…ross multiple test components
|
@canac I realized from working on this that Nearest Geographic Multiplier Location and the MHA inputs in "Your Information" step of Salary Calculator aren't strictly enforced/required in the UI (even before this PR). I'm thinking we probably want both of these enforced. I've made a follow up ticket in the backlog. |
Are you pointing out that they're optional fields? I believe the calculations treat missing a geo multiplier as None and missing MHA as 0 (which is a valid choice). Do stakeholders want us to force people to choose a value as opposed to leaving them blank? |
|
@canac Ah if they truly are optional, that makes sense, the MHA Request section is a quick change then. The fields display an asterisk (hinting required). Will be a quick no-jira. |
|
Yeah, I think removing the asterisk is a good call. Unless we want to make the MHA fields required. |

Description
https://jira.cru.org/browse/MPDX-9766
Testing
Considerations:
Checklist:
/pr-reviewcommand locally and fixed any relevant suggestions