themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.82k stars 406 forks source link

Datepicker required is not working. #1195

Open drokbers opened 8 months ago

drokbers commented 8 months ago

Summary

I'm using date picker like the one below but it's never required. Users can submit the form with an empty datepicker, and additionally, when a field is marked as required in an input field, a red asterisk (*) appears above it, but it doesn't appear above the datepicker.

<Datepicker required title="Start date" theme={customTheme} showClearButton showTodayButton={false} className="w-1/2" datepicker-format="dd/mm/yyyy" onSelectedDateChanged={handleDateChange("start_date")} value={formattedStartDate} />

Context

I tried in chrome, brave and safari and all has same bug.

tulup-conner commented 7 months ago

Hi there, thanks for bring this up. I do believe required is passed - the issue is that the default <Datepicker> state is always the current date, so the browser interprets it as filled immediately. Still a bug of course.

ddiasfront commented 7 months ago

Hi there, thanks for bring this up. I do believe required is passed - the issue is that the default <Datepicker> state is always the current date, so the browser interprets it as filled immediately. Still a bug of course.

I would head up to https://github.com/themesberg/flowbite-react/pull/1190 and see if these breaking changes might be related and fix this too, not sure.

drokbers commented 7 months ago

Hi there, thanks for bring this up. I do believe required is passed - the issue is that the default <Datepicker> state is always the current date, so the browser interprets it as filled immediately. Still a bug of course.

Yes, but I cannot do anything to prevent the submit process when the user does not select any date. Thank you for looking into this.

mattslight commented 6 months ago

This also ties in with a placeholder for the Datepicker if no date is currently selected...

<Datepicker
            placeholder="Please select date of birth"
                        ...
          />