From c61dbcf57c354760c8eec687c6c9d312c6a6b4d7 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:17:26 +0000 Subject: [PATCH] fix(nc-gui): field validation issue --- .../nc-gui/components/smartsheet/Form.vue | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index f0dd0ed036..2c4386dd25 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -62,7 +62,7 @@ const { $api, $e } = useNuxtApp() const { isUIAllowed } = useRoles() -let formState = reactive({}) +let formState = reactive>({}) const secondsRemain = ref(0) @@ -158,8 +158,9 @@ async function submitForm() { } async function clearForm() { - formState = {} + formState = reactive>({}) state.value = {} + await formRef.value.clearValidate() reloadEventHook.trigger() } @@ -428,6 +429,20 @@ watch(view, (nextView) => { } }) +watch([formState, state.value], async () => { + for (const virtualField in state.value) { + if (!formState[virtualField]) { + formState[virtualField] = state.value[virtualField] + } + } + + try { + await formRef.value?.validateFields([...Object.keys(formState)]) + } catch (e: any) { + e.errorFields.map((f: Record) => console.error(f.errors.join(','))) + } +}) + watch(activeRow, (newValue) => { if (newValue) { document @@ -892,7 +907,6 @@ useEventListener(