Skip to content

fix(#463): add validation for empty doubt submissions#679

Merged
knoxiboy merged 2 commits into
knoxiboy:mainfrom
dreynox:fix/empty-doubt-validation-463
Jun 20, 2026
Merged

fix(#463): add validation for empty doubt submissions#679
knoxiboy merged 2 commits into
knoxiboy:mainfrom
dreynox:fix/empty-doubt-validation-463

Conversation

@dreynox

@dreynox dreynox commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

User description

UI Enhancement: Add validation message when submitting empty doubt/question input #463

Related Issue

Closes #463


Type of Change

  • Bug Fix
  • UI Enhancement
  • Documentation Update
  • Refactor
  • Chore

Description

This PR resolves an issue where users could attempt to submit a doubt/question without entering any content and not receive any clear validation feedback. Previously, the submit button was disabled when the input was invalid, but since it provided no actionable feedback, users were left confused thinking the submission process was broken.

The fix updates the form logic by making the submit button clickable even when fields are empty and moving the strict validation checks inside the handleSubmit function. It now uses sonner toast notifications to provide clear error messages ("Please enter a subject before submitting." and "Please enter your doubt before submitting.") to explicitly inform the user why the form cannot be submitted, greatly improving overall UX and accessibility.


Changes Made

  • src/components/AskDoubt.tsx
    • Added subject validation inside handleSubmit to show a toast error if the subject field is empty.
    • Added content validation inside handleSubmit to show a toast error if both the doubt text and image attachments are missing.
    • Removed content validation dependencies from the submit button's disabled property, ensuring users can click the button and trigger the new validation feedback instead of the button being silently unclickable.

Screenshots / Recordings

(If applicable, you can attach screenshots or a screen recording here showing the new red toast validation error appearing when clicking submit on an empty form.)


How to Verify Locally

  1. Start the development server: npm run dev
  2. Open the DoubtDesk web application and navigate to the Doubt Submission section (open the "Ask Doubt" modal).
  3. Leave both the subject and the content fields completely empty.
  4. Click the "Post Doubt" button.
  5. Expected: A clear red toast notification should appear stating "Please enter a subject before submitting."
  6. Fill in the subject, but leave the doubt content/attachment empty, and click submit.
  7. Expected: A clear red toast notification should appear stating "Please enter your doubt before submitting." and the form will be prevented from sending the API request.

Checklist

  • My code follows the project's coding style
  • I have tested my changes locally
  • I have updated the documentation if required
  • No existing functionality has been broken
  • All checks and linting pass successfully (verified via tsc --noEmit)

GSSoC'26 Contributor Declaration

  • I confirm that I am a participant of GSSoC'26
  • I have followed the contribution guidelines of this project
  • This PR is ready for review


CodeAnt-AI Description

Add clear error messages when users try to submit a doubt without required input

What Changed

  • Submitting without a subject now shows a clear error instead of failing silently
  • Submitting without any doubt text or image now shows a clear error explaining what is missing
  • The Post Doubt button stays clickable so users can trigger the validation message instead of seeing a blocked submit

Impact

✅ Clearer doubt submission errors
✅ Fewer failed posts with no feedback
✅ Less confusion when required fields are empty

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Bug Fixes
    • Improved form validation with clearer error feedback when submitting with blank subject, content, or missing attachments.
    • Enhanced submit button responsiveness by relocating validation checks to the submission handler for better user interaction.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@dreynox is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@codeant-ai

codeant-ai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@github-actions github-actions Bot added gssoc'26 GSSoC program issue level:intermediate Intermediate level task type:bug Bug fix size/xs labels Jun 20, 2026
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@dreynox, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 59 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ed72d20d-0d05-42ec-a8a7-04f3ac6dbf2d

📥 Commits

Reviewing files that changed from the base of the PR and between ae78bcc and 21f02a0.

📒 Files selected for processing (1)
  • src/components/AskDoubt.tsx

Walkthrough

In AskDoubt.tsx, form submission validation is moved from the button's disabled prop into handleSubmit. Two explicit toast-error checks are added: one for a blank subject and one for missing content or attachment. The button's disabled condition is reduced to only isSubmitting.

Changes

AskDoubt Form Validation

Layer / File(s) Summary
handleSubmit validation and button disabled state
src/components/AskDoubt.tsx
handleSubmit replaces a silent combined early-return with two explicit toast error checks: one for a blank trimmed subject and one for missing content and attachment. The submit button's disabled prop is simplified from multiple content/subject/length conditions down to only isSubmitting.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • knoxiboy/DoubtDesk#560: Directly modifies the same AskDoubt.tsx component to handle empty subject validation, overlapping with this PR's subject-blank toast check in handleSubmit.

Suggested labels

gssoc'26, level:beginner, quality:clean, type:bug

Suggested reviewers

  • knoxiboy
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix(#463): add validation for empty doubt submissions' clearly and specifically describes the main change - adding validation for empty submissions to address issue #463.
Linked Issues check ✅ Passed The code changes implement all primary objectives from issue #463: moving validation into handleSubmit to display toast notifications for empty subject and content/attachment fields, preventing empty submissions.
Out of Scope Changes check ✅ Passed All changes in src/components/AskDoubt.tsx are directly related to issue #463 - modifying validation logic and submit button behavior to add validation feedback for empty doubt submissions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

@coderabbitai review

@codeant-ai codeant-ai Bot added the size:XS label Jun 20, 2026
@github-actions github-actions Bot removed the size:XS label Jun 20, 2026
Comment on lines +318 to +321
if (!subject.trim()) {
toast.error("Please enter a subject before submitting.");
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This custom empty-subject validation will not reliably run because the subject input still uses native HTML required, which blocks form submission before handleSubmit executes. As a result, users won't consistently see the new toast message and will get browser-native validation instead. Remove native blocking validation for that field (or disable native form validation) so this check actually controls the UX. [incomplete implementation]

Severity Level: Major ⚠️
- ⚠️ Subject-empty validation uses browser message instead of toast.
- ⚠️ Ask Doubt modal UX inconsistent with new validation behavior.
Steps of Reproduction ✅
1. Run the app (e.g., `npm run dev`) and open the public rooms page where the ask modal is
wired, implemented at `src/app/public-rooms/page.tsx:20-31`, then click the "Be the first
to ask" button (`page.tsx:7-13`) to set `isAskModalOpen` to true and render `<AskDoubt ...
/>` (`page.tsx:20-29`).

2. In the rendered `AskDoubt` modal (`src/components/AskDoubt.tsx:391-773`), focus the
"Subject / Topic" input defined at `AskDoubt.tsx:416-427` which includes the `required`
attribute on the `<input type="text" ... required />`.

3. Delete all text from the subject field so it is completely empty, then type a
sufficiently long question (≥ 20 characters) into the textarea at `AskDoubt.tsx:474-488`
so that `hasContent` is true and `isTooShort` is false, and leave attachments empty so
only the subject is invalid.

4. Click the "Post Doubt" submit button defined at `AskDoubt.tsx:761-767`; because the
subject input is marked `required` (`AskDoubt.tsx:426`), the browser's native HTML5
validation prevents the form submission and blocks the React `onSubmit={handleSubmit}`
handler at `AskDoubt.tsx:307-389` from running, so the custom toast-based check `if
(!subject.trim()) { toast.error("Please enter a subject before submitting."); return; }`
at `AskDoubt.tsx:318-321` never executes and users see only the browser's default "Please
fill out this field" tooltip instead of the intended toast error.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/components/AskDoubt.tsx
**Line:** 318:321
**Comment:**
	*Incomplete Implementation: This custom empty-subject validation will not reliably run because the subject input still uses native HTML `required`, which blocks form submission before `handleSubmit` executes. As a result, users won't consistently see the new toast message and will get browser-native validation instead. Remove native blocking validation for that field (or disable native form validation) so this check actually controls the UX.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/AskDoubt.tsx (1)

319-324: ⚡ Quick win

Move new toast copy to constants instead of inline literals.

At Line 319 and Line 323, the new user-facing messages are hardcoded. Please extract them into shared constants (e.g., @/lib/copy-constants) for consistency and easier localization/copy updates.

As per coding guidelines, "**/*.tsx: ... No hardcoded strings (use constants)."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/AskDoubt.tsx` around lines 319 - 324, The hardcoded string
literals used in the toast.error calls at lines 319 and 323 within the AskDoubt
component violate the coding guidelines that require using constants instead of
inline strings. Extract both toast error messages ("Please enter a subject
before submitting." and "Please enter your doubt before submitting.") into a
shared constants file such as `@/lib/copy-constants` with descriptive constant
names. Then import these constants into AskDoubt.tsx and replace the hardcoded
strings in the toast.error() calls with references to the newly created
constants.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/AskDoubt.tsx`:
- Around line 318-320: The custom subject validation toast at line 319 in the
handleSubmit function is unreachable because the form's native required
attribute on the subject input field (line 426) prevents form submission before
handleSubmit executes. Add the noValidate attribute to the form element that
wraps both the subject input and submit button to disable native browser
validation and allow your custom validation logic in handleSubmit to run,
ensuring the toast message displays consistently when subject is empty.

---

Nitpick comments:
In `@src/components/AskDoubt.tsx`:
- Around line 319-324: The hardcoded string literals used in the toast.error
calls at lines 319 and 323 within the AskDoubt component violate the coding
guidelines that require using constants instead of inline strings. Extract both
toast error messages ("Please enter a subject before submitting." and "Please
enter your doubt before submitting.") into a shared constants file such as
`@/lib/copy-constants` with descriptive constant names. Then import these
constants into AskDoubt.tsx and replace the hardcoded strings in the
toast.error() calls with references to the newly created constants.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e4b1eee4-0389-46dc-b537-b74e513eac5b

📥 Commits

Reviewing files that changed from the base of the PR and between 885f5b7 and ae78bcc.

📒 Files selected for processing (1)
  • src/components/AskDoubt.tsx

Comment thread src/components/AskDoubt.tsx
@dreynox

dreynox commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Hi @knoxiboy , please review this PR and let me know if any changes are required. Thank You.

@knoxiboy knoxiboy added level:beginner Beginner level task and removed level:intermediate Intermediate level task labels Jun 20, 2026
@knoxiboy
knoxiboy merged commit 6d05b3e into knoxiboy:main Jun 20, 2026
22 of 23 checks passed
@github-actions github-actions Bot added gssoc:approved Approved for GSSoC quality:clean Clean code quality and removed size/xs review-needed labels Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:beginner Beginner level task quality:clean Clean code quality type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UI Enhancement: Add validation message when submitting empty doubt/question input

2 participants