Skip to content

Required radio button#5985

Merged
PeerRich merged 2 commits intomainfrom
5950-cal-579-highlight-required
Dec 12, 2022
Merged

Required radio button#5985
PeerRich merged 2 commits intomainfrom
5950-cal-579-highlight-required

Conversation

@sean-brydon
Copy link
Copy Markdown
Member

What does this PR do?

Display a nicer error message to the user when a radio option is required.

CleanShot 2022-12-12 at 11 32 26@2x

@Jaibles Do you have a design for required radio buttons? Will come back to this if one gets created

@linear
Copy link
Copy Markdown

linear Bot commented Dec 12, 2022

CAL-579 Highlight required inputs instead of yellow warning message

Issue Summary

We have updated one of the Cal.Com events with text inputs, now it has radio buttons.

  1. And when I navigate to the event page with text inputs
  2. And don't click on any of the obligatory inputs
  3. Click on the "Confirm" button

Actual Result: I see a yellow warning message - **Could not book the meeting. invalid_type in 'customInputs,0,value':**
which does not explain well to the average user why he cannot book the meeting

Expected Result: I expect them to be highlighted in red

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 12, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cal ✅ Ready (Inspect) Visit Preview Dec 12, 2022 at 11:53AM (UTC)

Comment on lines +318 to +332
if (eventType.customInputs.length > 0) {
// find all required custom inputs and ensure they are filled out in the booking form
const requiredCustomInputs = eventType.customInputs.filter((input) => input.required);
const missingRequiredCustomInputs = requiredCustomInputs.filter(
(input) => !booking?.customInputs?.[input.id]
);
if (missingRequiredCustomInputs.length > 0) {
missingRequiredCustomInputs.forEach((input) => {
bookingForm.setError(`customInputs.${input.id}`, {
type: "required",
});
});
return;
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We have to do this cause required prop with radix doesnt seem to work with rhf

{input.label}
className={classNames(
"mb-1 block text-sm font-medium text-gray-700 transition-colors dark:text-white",
bookingForm.formState.errors.customInputs?.[input.id] && "!text-red-700"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For now all the other errors are handled by rhf

Comment on lines +783 to +786
{bookingForm.formState.errors.customInputs?.[input.id] && (
<div className="mt-px flex items-center text-xs text-red-700 ">
<p>{t("required")}</p>
</div>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add required tag

@PeerRich PeerRich merged commit df4df68 into main Dec 12, 2022
@PeerRich PeerRich deleted the 5950-cal-579-highlight-required branch December 12, 2022 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CAL-579] Highlight required inputs instead of yellow warning message

3 participants