From ee24ceaff1f9be994f7cdfbe9ff9795362cef1a2 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 3 Nov 2025 15:45:42 +0700 Subject: [PATCH] refactor(FE-208,212): update PurchaseRequestForm to reset location fields on area change, improve handling of location value and dependencies --- src/components/pages/purchase/form/PurchaseRequestForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/pages/purchase/form/PurchaseRequestForm.tsx b/src/components/pages/purchase/form/PurchaseRequestForm.tsx index 3607d1a1..ef213ebd 100644 --- a/src/components/pages/purchase/form/PurchaseRequestForm.tsx +++ b/src/components/pages/purchase/form/PurchaseRequestForm.tsx @@ -391,7 +391,9 @@ const PurchaseRequestForm = ({ formik.setFieldValue('area_id', (area as OptionType)?.value || 0); // Reset area dependent fields - formik.setFieldValue('location', null); + formik.setFieldTouched('location', false); + formik.setFieldValue('location', undefined); + formik.setFieldTouched('location_id', false); formik.setFieldValue('location_id', 0); setLocationSelectInputValue(''); @@ -590,7 +592,7 @@ const PurchaseRequestForm = ({ ? 'Pilih Area terlebih dahulu' : 'Pilih Lokasi...' } - value={formik.values.location} + value={formik.values.area_id ? formik.values.location : null} onChange={locationChangeHandler} options={locationOptions} onInputChange={setLocationSelectInputValue} @@ -601,6 +603,7 @@ const PurchaseRequestForm = ({ errorMessage={formik.errors.location_id as string} isDisabled={type === 'detail' || !formik.values.area_id} isClearable={type !== 'detail' && !!formik.values.area_id} + key={`location-${formik.values.area_id}`} />