-
Hi everyone, Here's the DateTimePicker component: https://mui.com/x/react-date-pickers/date-time-picker/ Here's the DateTimePicker API: https://mui.com/x/api/date-pickers/date-time-picker/ |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
You can use the const { control, handleSubmit } = useForm({
defaultValues: {
date: null as Dayjs | null
}
});
/*........*/
<Controller
control={control}
name="date"
rules={{ required: true }}
render={({ field }) => {
return (
<DateTimePicker
label="Date"
value={field.value}
inputRef={field.ref}
onChange={(date) => {
field.onChange(date);
}}
/>
);
}}
/> |
Beta Was this translation helpful? Give feedback.
-
Thank you! @Sajarin-M .
.
.
const { watch, control } = useFormContext<SearchForm>();
.
.
.
<Controller
control={control}
defaultValue={dayjs().startOf("D")}
name="startDate"
rules={{
required: {
value: true,
message: "Start date is required",
},
}}
render={({ field: { onChange, value, ref } }) => (
<DateTimePicker
label="Start Date"
disableFuture
onChange={onChange}
onAccept={onChange}
value={value}
inputRef={ref}
/>
)}
/> |
Beta Was this translation helpful? Give feedback.
-
with this onBlur is not working, even though im sending through the slot props |
Beta Was this translation helpful? Give feedback.
-
I'm using this with react hook form too but when there is any validation error the control doesn't go to the datepicker. The field is not focused when we click submit and we have any error with it. Am I missing something here?
|
Beta Was this translation helpful? Give feedback.
-
when i check what is the data in handleSubmit, i am getting old value for datepicker. i also have to mention that i use setValue to set the formdata with info from redux store. wihtout using setValue everything works fine. |
Beta Was this translation helpful? Give feedback.
-
this is what worked for me |
Beta Was this translation helpful? Give feedback.
-
Idk maybe the key is change
|
Beta Was this translation helpful? Give feedback.
You can use the
Controller
component, like:CSB Demo