fix: show field-level validation errors on New Leave Request form - #27
Merged
Conversation
Required fields (start/end date, reason) now show inline red-border error styling with helper text on empty submit, instead of relying on the browser's native required-field tooltip.
There was a problem hiding this comment.
Pull request overview
This PR updates the “New Leave Request” dialog in the web app to show inline, field-level validation errors (red borders + helper text) for required inputs instead of relying on browser-native required-field tooltips.
Changes:
- Added
fieldErrorsstate plus avalidateForm()helper to gate submission and populate inline errors. - Wired MUI
TextFielderror/helperTextprops for start/end date and reason, and attempted to clear per-field errors on change. - Reset
fieldErrorson successful submit and on dialogonClose.
Suppressed comments (3)
auditra web app/src/pages/shared/MyLeaveRequests.jsx:311
- This handler clears
fieldErrors.start_dateusing a spread offieldErrorsfrom the render closure (setFieldErrors({ ...fieldErrors, ... })). In React this risks lost updates when multiple fieldErrors updates are batched, because each call may start from a stale snapshot. Use functional setState to merge against the latest state; this pattern is repeated elsewhere in the file.
onChange={(e) => {
handleStartDateChange(e.target.value);
if (fieldErrors.start_date) setFieldErrors({ ...fieldErrors, start_date: undefined });
}}
auditra web app/src/pages/shared/MyLeaveRequests.jsx:321
- Clearing
fieldErrors.end_dateviasetFieldErrors({ ...fieldErrors, end_date: undefined })can overwrite other error-state updates due to spreading a stalefieldErrorsvalue. PrefersetFieldErrors(prev => ({ ...prev, end_date: undefined }))(or delete the key) to avoid lost updates; same issue exists in other onChange handlers.
onChange={(e) => {
setForm({ ...form, end_date: e.target.value });
if (fieldErrors.end_date) setFieldErrors({ ...fieldErrors, end_date: undefined });
}}
auditra web app/src/pages/shared/MyLeaveRequests.jsx:333
- The reason field clears its error using
setFieldErrors({ ...fieldErrors, reason: undefined }), which can drop other simultaneous/batched updates because it spreads a stale closure value. Use a functional update to merge with the latest state; same pattern is present in other fields in this dialog.
onChange={(e) => {
setForm({ ...form, reason: e.target.value });
if (fieldErrors.reason) setFieldErrors({ ...fieldErrors, reason: undefined });
}}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+288
to
+291
| onChange={(e) => { | ||
| setForm({ ...form, start_date: e.target.value, end_date: e.target.value }); | ||
| if (fieldErrors.start_date) setFieldErrors({ ...fieldErrors, start_date: undefined }); | ||
| }} |
|
|
||
| {/* New Request Dialog */} | ||
| <Dialog open={dialogOpen} onClose={() => setDialogOpen(false)} maxWidth="sm" fullWidth> | ||
| <Dialog open={dialogOpen} onClose={() => { setDialogOpen(false); setFieldErrors({}); }} maxWidth="sm" fullWidth> |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Required fields (start/end date, reason) now show inline red-border error styling with helper text on empty submit, instead of relying on the browser's native required-field tooltip.