-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added required field validation and scroll before submit for questionnaire forms #10169
Added required field validation and scroll before submit for questionnaire forms #10169
Conversation
WalkthroughThe pull request introduces changes to two components: Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx (1)
Line range hint
20-29
: Add input validation for numeric parsing and bounds.Consider adding validation to handle:
- Invalid numeric inputs that could cause parsing errors
- Min/max bounds if applicable to the questionnaire context
const handleChange = (value: string) => { const emptyValue = value === ""; + if (emptyValue) { + updateQuestionnaireResponseCB({ + ...questionnaireResponse, + values: [{ type: "number", value: undefined }], + }); + return; + } + + // Validate numeric input + const numStr = value.trim(); + if (!/^-?\d*\.?\d*$/.test(numStr)) { + return; // Invalid numeric input + } + const numericValue = question.type === "decimal" ? parseFloat(value) : parseInt(value); + + // Optional: Add bounds validation if min/max are provided + if (question.min !== undefined && numericValue < question.min) return; + if (question.max !== undefined && numericValue > question.max) return; updateQuestionnaireResponseCB({ ...questionnaireResponse, values: [ { type: "number", - value: emptyValue ? undefined : numericValue, + value: numericValue, }, ], }); };src/components/Questionnaire/QuestionnaireForm.tsx (1)
229-233
: Consider using a translation key specific to field type.The current implementation uses a generic "field_required" message. Consider using field-type-specific messages for better user experience.
errors.push({ question_id: q.id, error: t("field_required"), type: "validation_error", - msg: t("field_required"), + msg: t(`${q.type}_field_required`), });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx
(2 hunks)src/components/Questionnaire/QuestionnaireForm.tsx
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: cypress-run (1)
🔇 Additional comments (4)
src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx (1)
Line range hint
20-29
: LGTM! Improved empty value handling.The change correctly handles empty values by setting them to
undefined
instead of attempting numeric conversion.src/components/Questionnaire/QuestionnaireForm.tsx (3)
165-167
: LGTM! Added null safety check.Good defensive programming practice to handle cases where result.data.errors might be undefined.
203-256
: LGTM! Comprehensive validation implementation.Well-structured implementation that:
- Clears existing errors
- Validates all required fields
- Implements smooth scroll to the first error
263-263
: LGTM! Using validated forms for submission.Correctly uses the validated forms state for submission processing.
Also applies to: 281-281
@Jacobjeevan Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌 |
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit