From 52791241300b2d48dbd7d4c2d398c50db94cddea Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 27 Jan 2025 10:47:43 +0300 Subject: [PATCH] fix static leases form --- .../Settings/Dhcp/StaticLeases/Form.tsx | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx b/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx index 28ab7241..9b057c73 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx +++ b/client/src/components/Settings/Dhcp/StaticLeases/Form.tsx @@ -14,6 +14,7 @@ import { import { toggleLeaseModal } from '../../../../actions'; import { RootState } from '../../../../initialState'; +import { Input } from '../../../ui/Controls/Input'; type Props = { initialValues?: { @@ -27,15 +28,21 @@ type Props = { cidr?: string; isEdit?: boolean; onSubmit: (data: any) => void; -} +}; export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit }: Props) => { const { t } = useTranslation(); const dispatch = useDispatch(); const dynamicLease = useSelector((store: RootState) => store.dhcp.leaseModalConfig, shallowEqual); - const { handleSubmit, control, reset, formState: { isSubmitting, isDirty } } = useForm({ + const { + handleSubmit, + control, + reset, + formState: { isSubmitting, isDirty }, + } = useForm({ defaultValues: initialValues, + mode: 'onBlur', }); const onClick = () => { @@ -51,13 +58,14 @@ export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit } name="mac" control={control} rules={{ validate: { required: validateRequiredValue, mac: validateMac } }} - render={({ field }) => ( - ( + field.onChange(normalizeMac(e.target.value))} /> )} @@ -68,17 +76,20 @@ export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit } ( - ( + )} @@ -89,11 +100,12 @@ export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit } ( - ( + )} @@ -105,18 +117,18 @@ export const Form = ({ initialValues, processingAdding, cidr, isEdit, onSubmit }