Skip to content

Commit

Permalink
feat: handle empty validation on handlechange
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Nov 27, 2024
1 parent da6a8ff commit ae41a24
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/components/form/fields/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ export function DateField({

const { input, meta } = useField<string | undefined>(name)

Check warning on line 34 in src/components/form/fields/DateField.tsx

View workflow job for this annotation

GitHub Actions / lint

'meta' is assigned a value but never used

useEffect(() => {
if (input.value === '' && meta.touched && required) {
const handleChange: CalendarInputProps['onDateSelect'] = (
payload: {
calendarDateString: string
validation?: ValidationProps
} | null
) => {
if (!payload?.calendarDateString && required) {
setValidation({
error: true,
valid: false,
validationCode: 'EMPTY',
validationText: i18n.t('Required'),
})
} else {
setValidation(payload?.validation || { error: false })
}
}, [required, input.value, meta.touched])

const handleChange: CalendarInputProps['onDateSelect'] = (
payload: {
calendarDateString: string
validation?: ValidationProps
} | null
) => {
setValidation(payload?.validation || { error: false })
input.onChange(payload?.calendarDateString || '')
input.onBlur()
}
Expand Down

0 comments on commit ae41a24

Please sign in to comment.