Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ function FieldEditDialog({
//resolver: zodResolver(fieldSchema),
});
const formFieldType = fieldForm.getValues("type");
const fieldName = fieldForm.watch("name");

useEffect(() => {
if (!formFieldType) {
Expand Down Expand Up @@ -713,6 +714,27 @@ function FieldEditDialog({
<FieldWithLengthCheckSupport containerClassName="mt-6" fieldForm={fieldForm} />
) : null}

{formFieldType === "multiemail" && fieldName === "guests" && (
<InputField
{...fieldForm.register("maxEntries", {
setValueAs: (value) => {
if (value === "") {
return undefined;
}
const parsed = Number(value);
if (Number.isNaN(parsed) || !Number.isInteger(parsed) || parsed < 1) {
return undefined;
}
return parsed;
},
Comment on lines +720 to +729

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important

[Logic] The setValueAs function currently swallows validation errors (like non-integers or values less than 1) by returning undefined, which zod treats as a valid optional value. This means invalid inputs (e.g. "1.5" or "-1") will simply unset the limit rather than showing a validation error.

Simiplifying this to just type coercion allows the Zod schema (z.number().int().min(1)) to handle the validation and provide proper error feedback to the user.

Context for Agents
The `setValueAs` function currently swallows validation errors (like non-integers or values less than 1) by returning `undefined`, which `zod` treats as a valid optional value. This means invalid inputs (e.g. "1.5" or "-1") will simply unset the limit rather than showing a validation error.

Simiplifying this to just type coercion allows the Zod schema (`z.number().int().min(1)`) to handle the validation and provide proper error feedback to the user.

File: apps/web/modules/event-types/components/tabs/advanced/FormBuilder.tsx
Line: 729

})}
containerClassName="mt-6"
label={t("max_attendees")}
type="number"
min={1}
/>
)}

{formFieldType === "email" && (
<InputField
{...fieldForm.register("requireEmails")}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"min_characters": "Min. Characters",
"min_characters_required": "Min. {{count}} characters required",
"max_characters_allowed": "Max. {{count}} characters allowed",
"max_attendees": "Maximum attendees",
"max_attendees_allowed": "Maximum {{count}} attendees allowed",
"calcom_explained": "{{appName}} provides scheduling infrastructure for absolutely everyone.",
"calcom_explained_new_user": "Finish setting up your {{appName}} account! You're just a few steps away from solving all your scheduling problems.",
"have_any_questions": "Have questions? We're here to help.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type SelectLikeComponentPropsRAQB<TVal extends string | string[] = string

export type TextLikeComponentProps<TVal extends string | string[] | boolean = string> = CommonProps<TVal> & {
name?: string;
maxEntries?: number;
};

export type TextLikeComponentPropsRAQB<TVal extends string | boolean = string> =
Expand Down
7 changes: 7 additions & 0 deletions packages/features/bookings/lib/getBookingResponsesSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ function preprocess<T extends z.ZodType>({
}

const emails = emailsParsed.data;
if (typeof bookingField.maxEntries === "number" && emails.length > bookingField.maxEntries) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: m("max_attendees_allowed", { count: bookingField.maxEntries }),
});
continue;
}
emails.sort().some((item, i) => {
if (item === emails[i + 1]) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: m("duplicate_email") });
Expand Down
17 changes: 16 additions & 1 deletion packages/features/form-builder/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ export const Components: Record<FieldType, Component> = {
factory: function MultiEmail({ value, readOnly, label, setValue, ...props }) {
const placeholder = props.placeholder;
const { t } = useLocale();
value = value || [];
const maxEntries = props.maxEntries;
const listValue = value || [];
const hasReachedLimit =
typeof maxEntries === "number" && maxEntries > 0 && listValue.length >= maxEntries;
value = listValue;
return (
<>
{value.length ? (
Expand Down Expand Up @@ -293,13 +297,20 @@ export const Components: Record<FieldType, Component> = {
color="minimal"
StartIcon="user-plus"
className="my-2.5"
disabled={hasReachedLimit}
onClick={() => {
if (hasReachedLimit) {
return;
}
value.push("");
setValue(value);
}}>
{t("add_another")}
</Button>
)}
{!readOnly && typeof maxEntries === "number" && maxEntries > 0 && (
<p className="text-subtle text-xs">{t("max_attendees_allowed", { count: maxEntries })}</p>
)}
</div>
) : (
<></>
Expand All @@ -311,7 +322,11 @@ export const Components: Record<FieldType, Component> = {
color="minimal"
variant="button"
StartIcon="user-plus"
disabled={hasReachedLimit}
onClick={() => {
if (hasReachedLimit) {
return;
}
value.push("");
setValue(value);
}}
Expand Down
1 change: 1 addition & 0 deletions packages/features/form-builder/FormBuilderField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export const ComponentForField = ({
placeholder={field.placeholder}
name={field.name}
label={field.label}
maxEntries={field.maxEntries}
readOnly={readOnly}
value={value as string[]}
setValue={setValue as (arg: typeof value) => void}
Expand Down
6 changes: 6 additions & 0 deletions packages/prisma/zod-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,12 @@ export const baseFieldSchema = z.object({
*/
maxLength: z.number().optional(),

/**
* It is the maximum number of entries that can be provided for list fields.
* It is used for types like `multiemail`.
*/
maxEntries: z.number().int().min(1).optional(),

// Emails that needs to be excluded
excludeEmails: excludeOrRequireEmailSchema.optional(),
// Emails that need to be required
Expand Down