fix: handle default values in date select
This commit is contained in:
@@ -76,19 +76,17 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (year && month && day) {
|
const newDate = dt()
|
||||||
const newDate = dt()
|
.year(Number(year))
|
||||||
.year(Number(year))
|
.month(Number(month) - 1)
|
||||||
.month(Number(month) - 1)
|
.date(Number(day))
|
||||||
.date(Number(day))
|
|
||||||
|
|
||||||
if (newDate.isValid()) {
|
if (newDate.isValid()) {
|
||||||
setValue(name, newDate.format("YYYY-MM-DD"), {
|
setValue(name, newDate.format("YYYY-MM-DD"), {
|
||||||
shouldDirty: true,
|
shouldDirty: true,
|
||||||
shouldTouch: true,
|
shouldTouch: true,
|
||||||
shouldValidate: true,
|
shouldValidate: true,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [year, month, day, setValue, name, formState.isSubmitting])
|
}, [year, month, day, setValue, name, formState.isSubmitting])
|
||||||
|
|
||||||
@@ -106,6 +104,16 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
|
|||||||
console.warn("Known error for parse date in DateSelect: ", error)
|
console.warn("Known error for parse date in DateSelect: ", error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (formState.isSubmitting) return
|
||||||
|
|
||||||
|
if (!(day && month && year) && dateValue) {
|
||||||
|
setValue(DateName.day, Number(dateValue.day))
|
||||||
|
setValue(DateName.month, Number(dateValue.month))
|
||||||
|
setValue(DateName.year, Number(dateValue.year))
|
||||||
|
}
|
||||||
|
}, [setValue, formState.isSubmitting, dateValue, day, month, year])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DatePicker
|
<DatePicker
|
||||||
aria-label={intl.formatMessage({ id: "Select date of birth" })}
|
aria-label={intl.formatMessage({ id: "Select date of birth" })}
|
||||||
|
|||||||
Reference in New Issue
Block a user