Skip to content

fix: skip email validation for hidden field#24382

Closed
Saumya-Kushwah wants to merge 3 commits intocalcom:mainfrom
Saumya-Kushwah:fix/email-validation-hidden-field
Closed

fix: skip email validation for hidden field#24382
Saumya-Kushwah wants to merge 3 commits intocalcom:mainfrom
Saumya-Kushwah:fix/email-validation-hidden-field

Conversation

@Saumya-Kushwah
Copy link

What does this PR do?

This PR fixes a regression where email validation was incorrectly running on hidden email fields, preventing users from completing bookings even when the email was prefilled

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

Timeline.1.mov

Image Demo (if applicable):

image

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox. — N/A: Bug fix, no user-facing documentation changes required.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Setup:

  • Created event type "Test Booking"
  • Configured email field as Hidden in Booking Questions
  • Left other fields (Name, Phone) visible

Test Execution:

  1. Opened booking page in incognito browser
  2. Filled required fields (Name: "Music", Phone: "+911556448644")
  3. Email field was NOT visible (hidden as configured)
  4. Clicked "Book"

Result:

  • Booking completed successfully
  • Confirmation page displayed: "This meeting is scheduled"
  • No {email}email_validation_error in console
  • Hidden email field did not block booking

@Saumya-Kushwah Saumya-Kushwah requested a review from a team as a code owner October 9, 2025 09:48
@CLAassistant
Copy link

CLAassistant commented Oct 9, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added booking-page area: booking page, public booking page, booker Medium priority Created by Linear-GitHub Sync 🐛 bug Something isn't working labels Oct 9, 2025
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Oct 9, 2025
@graphite-app graphite-app bot requested a review from a team October 9, 2025 09:48
@vercel
Copy link

vercel bot commented Oct 9, 2025

@Saumya-Kushwah is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Walkthrough

  • Updated type alias: View changed from ALL_VIEWS | (string & {}) to ALL_VIEWS | string in packages/features/bookings/lib/getBookingResponsesSchema.ts.
  • Adjusted JSON parsing to use a bare catch with an intentional ignore comment.
  • Modified email validation to skip validation when the email field is hidden; preserved existing conditional validation otherwise.
  • Updated required-field processing to skip hidden fields before validation, including for email.
  • Introduced early returns for hidden fields while maintaining partial vs non-partial schema behavior.
  • In packages/prisma/.env, removed the ../../.env reference.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR includes modifications such as adjusting the View type alias and updating JSON parsing behavior in getBookingResponsesSchema.ts, as well as removing a .env reference in packages/prisma, which are not related to skipping email validation for hidden fields. Please separate unrelated type alias, JSON parsing, and .env adjustments into their own pull requests to keep this fix focused on the email validation issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change to skip email validation for hidden fields and matches the main objective of the pull request.
Linked Issues Check ✅ Passed The changes introduce an early return for hidden email fields in the booking response schema, aligning with the requirement to skip validation when the email field is hidden, thereby satisfying the objectives of both linked issues (#24369 and CAL-6552).
Description Check ✅ Passed The pull request description clearly explains the regression being fixed, references the relevant issues, and outlines testing steps, so it is directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@dosubot dosubot bot added the bookings area: bookings, availability, timezones, double booking label Oct 9, 2025
@pull-request-size pull-request-size bot added size/S and removed size/XL labels Oct 9, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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)
packages/features/bookings/lib/getBookingResponsesSchema.ts (2)

98-107: Harden JSON parsing by validating the parsed shape

Bare catch is fine, but if JSON.parse(value) returns a non-object (e.g., a string), parsedValue becomes a primitive and later property access can misbehave. Guard the shape post-parse to keep the default when it’s not the expected object.

-          let parsedValue = {
-            optionValue: "",
-            value: "",
-          };
-          try {
-            parsedValue = JSON.parse(value);
-          } catch {
-            // Intentionally ignoring parse errors - using default empty parsedValue
-          }
+          let parsedValue: { optionValue: string; value: string } = {
+            optionValue: "",
+            value: "",
+          };
+          try {
+            const candidate = JSON.parse(value);
+            if (
+              candidate &&
+              typeof candidate === "object" &&
+              typeof (candidate as any).value === "string" &&
+              typeof (candidate as any).optionValue === "string"
+            ) {
+              parsedValue = candidate as { optionValue: string; value: string };
+            }
+          } catch {
+            // Intentionally ignoring parse errors - using default empty parsedValue
+          }

178-182: Skip email validation should use computed hidden and view applicability

Good fix. For consistency and to cover hideWhenJustOneOption and view mismatch, use the computed hidden and isFieldApplicableToCurrentView flags you already derive above.

-          // Skip validation if field is hidden
-          if (bookingField.hidden) {
+          // Skip validation if field is hidden or not applicable to the current view
+          if (hidden || !isFieldApplicableToCurrentView) {
             continue;
           }

Optional: consider applying the same early-skip for other field types (e.g., multiemail) so hidden fields never trigger validation noise when prefilled. Please confirm if product spec expects hidden fields to be fully ignored during validation.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bec49ef and 10f25ba.

📒 Files selected for processing (2)
  • packages/features/bookings/lib/getBookingResponsesSchema.ts (3 hunks)
  • packages/prisma/.env (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/prisma/.env
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/features/bookings/lib/getBookingResponsesSchema.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/bookings/lib/getBookingResponsesSchema.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/features/bookings/lib/getBookingResponsesSchema.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.
🧬 Code graph analysis (1)
packages/features/bookings/lib/getBookingResponsesSchema.ts (1)
packages/features/form-builder/schema.ts (1)
  • ALL_VIEWS (11-11)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests / Unit
🔇 Additional comments (1)
packages/features/bookings/lib/getBookingResponsesSchema.ts (1)

9-9: Type alias simplification looks good

Changing View to ALL_VIEWS | string is fine; no functional impact.

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

Labels

booking-page area: booking page, public booking page, booker bookings area: bookings, availability, timezones, double booking 🐛 bug Something isn't working community Created by Linear-GitHub Sync Medium priority Created by Linear-GitHub Sync size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Email validation error occurs when email field is hidden, even if prefilled — used to work before.”

2 participants