Browse Source

fix(gui-v2): reset validation and form state

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3188/head
Pranav C 2 years ago
parent
commit
bc8b1cd70a
  1. 10
      packages/nc-gui-v2/components/shared-view/Form.vue
  2. 14
      packages/nc-gui-v2/composables/useSharedFormViewStore.ts

10
packages/nc-gui-v2/components/shared-view/Form.vue

@ -31,13 +31,13 @@ function isRequired(_columnObj: Record<string, any>, required = false) {
<template v-else-if="submitted">
<div class="flex justify-center">
<div v-if="sharedView" style="min-width: 350px" class="mt-3">
<a-alert type="success" outlined :message="sharedView.success_msg || 'Successfully submitted form data'"> </a-alert>
<p v-if="sharedView.show_blank_form" class="text-xs text-gray-500 text-center">
<div v-if="sharedView.view" style="min-width: 350px" class="mt-3">
<a-alert type="success" outlined :message="sharedView.view.success_msg || 'Successfully submitted form data'"> </a-alert>
<p v-if="sharedView.view.show_blank_form" class="text-xs text-gray-500 text-center my-4">
New form will be loaded after {{ secondsRemain }} seconds
</p>
<div v-if="sharedView.submit_another_form" class="text-center">
<a-button color="primary" @click="submitted = false"> Submit Another Form</a-button>
<div v-if="sharedView.view.submit_another_form" class="text-center">
<a-button type="primary" @click="submitted = false"> Submit Another Form</a-button>
</div>
</div>
</div>

14
packages/nc-gui-v2/composables/useSharedFormViewStore.ts

@ -137,8 +137,6 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState(() =>
submitted.value = true
progress.value = false
additionalState.value = {}
formState.value = {}
await message.success(sharedView.value.success_msg || 'Saved successfully.')
} catch (e: any) {
@ -151,15 +149,23 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState(() =>
/** reset form if show_blank_form is true */
watch(submitted, (nextVal: boolean) => {
if (nextVal && sharedView.value.show_blank_form) {
if (nextVal && sharedView.value?.view?.show_blank_form) {
secondsRemain.value = 5
const intvl = setInterval(() => {
if (--secondsRemain.value < 0) {
secondsRemain.value = secondsRemain.value -1
if (secondsRemain.value < 0) {
submitted.value = false
clearInterval(intvl)
}
}, 1000)
}
/** reset form state and validation */
if(!nextVal){
additionalState.value = {}
formState.value = {}
v$.value?.$reset()
}
})
return {

Loading…
Cancel
Save