Browse Source

fix(nc-gui): prefill link issue after clicking clear form btn in form builder

pull/7786/head
Ramesh Mane 6 months ago
parent
commit
b9057d20b7
  1. 6
      packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
  2. 45
      packages/nc-gui/components/smartsheet/Form.vue
  3. 2
      packages/nc-gui/composables/useSharedFormViewStore.ts

6
packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue

@ -7,8 +7,6 @@ const { view: _view, $api } = useSmartsheetStoreOrThrow()
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
const { getBaseUrl, appInfo } = useGlobal() const { getBaseUrl, appInfo } = useGlobal()
const { t } = useI18n()
const { dashboardUrl } = useDashboard() const { dashboardUrl } = useDashboard()
const viewStore = useViewsStore() const viewStore = useViewsStore()
@ -428,14 +426,14 @@ watchEffect(() => {})
<a-radio-group <a-radio-group
v-if="formPreFill.preFillEnabled" v-if="formPreFill.preFillEnabled"
:value="formPreFill.preFilledMode || ''" :value="formPreFill.preFilledMode"
class="nc-field-layout-list" class="nc-field-layout-list"
data-testid="nc-modal-share-view__preFillMode" data-testid="nc-modal-share-view__preFillMode"
@update:value=" @update:value="
(value) => { (value) => {
formPreFill = { formPreFill = {
...formPreFill, ...formPreFill,
preFilledMode: value || '', preFilledMode: value,
} }
} }
" "

45
packages/nc-gui/components/smartsheet/Form.vue

@ -31,7 +31,6 @@ import {
onClickOutside, onClickOutside,
parseProp, parseProp,
provide, provide,
reactive,
ref, ref,
useDebounceFn, useDebounceFn,
useEventListener, useEventListener,
@ -82,7 +81,7 @@ const { getPossibleAttachmentSrc } = useAttachment()
const formRef = ref() const formRef = ref()
let formState = reactive<Record<string, any>>({}) const formState = ref<Record<string, any>>({})
const secondsRemain = ref(0) const secondsRemain = ref(0)
@ -112,7 +111,7 @@ const { fields, showAll, hideAll } = useViewColumnsOrThrow()
const { state, row } = useProvideSmartsheetRowStore( const { state, row } = useProvideSmartsheetRowStore(
meta, meta,
ref({ ref({
row: formState, row: formState.value,
oldRow: {}, oldRow: {},
rowMeta: { new: true }, rowMeta: { new: true },
}), }),
@ -198,7 +197,7 @@ const updateView = useDebounceFn(
const updatePreFillFormSearchParams = useDebounceFn(() => { const updatePreFillFormSearchParams = useDebounceFn(() => {
if (isLocked.value || !isUIAllowed('dataInsert')) return if (isLocked.value || !isUIAllowed('dataInsert')) return
const preFilledData = { ...formState, ...state.value } const preFilledData = { ...formState.value, ...state.value }
const searchParams = new URLSearchParams() const searchParams = new URLSearchParams()
@ -224,7 +223,7 @@ async function submitForm() {
} }
await insertRow({ await insertRow({
row: { ...formState, ...state.value }, row: { ...formState.value, ...state.value },
oldRow: {}, oldRow: {},
rowMeta: { new: true }, rowMeta: { new: true },
}) })
@ -235,7 +234,7 @@ async function submitForm() {
async function clearForm() { async function clearForm() {
if (isLocked.value || !isUIAllowed('dataInsert')) return if (isLocked.value || !isUIAllowed('dataInsert')) return
formState = reactive<Record<string, any>>({}) formState.value = {}
state.value = {} state.value = {}
await formRef.value?.clearValidate() await formRef.value?.clearValidate()
reloadEventHook.trigger() reloadEventHook.trigger()
@ -564,7 +563,7 @@ onMounted(async () => {
if (imageCropperData.value.src) { if (imageCropperData.value.src) {
URL.revokeObjectURL(imageCropperData.value.imageConfig.src) URL.revokeObjectURL(imageCropperData.value.imageConfig.src)
} }
preFillFormSearchParams.value = '' preFillFormSearchParams.value = ''
isLoadingFormView.value = true isLoadingFormView.value = true
@ -592,19 +591,25 @@ watch(view, (nextView) => {
} }
}) })
watch([formState, state.value], async () => { watch(
for (const virtualField in state.value) { [formState, state],
if (!formState[virtualField]) { async () => {
formState[virtualField] = state.value[virtualField] for (const virtualField in state.value) {
formState.value[virtualField] = state.value[virtualField]
} }
}
try { updatePreFillFormSearchParams()
await formRef.value?.validateFields([...Object.keys(formState)])
} catch (e: any) { try {
e.errorFields.map((f: Record<string, any>) => console.error(f.errors.join(','))) await formRef.value?.validateFields([...Object.keys(formState.value)])
} } catch (e: any) {
}) e.errorFields.map((f: Record<string, any>) => console.error(f.errors.join(',')))
}
},
{
deep: true,
},
)
watch(activeRow, (newValue) => { watch(activeRow, (newValue) => {
if (newValue) { if (newValue) {
@ -624,10 +629,6 @@ watch([focusLabel, activeRow], () => {
} }
}) })
watch([formState, state], () => {
updatePreFillFormSearchParams()
})
useEventListener( useEventListener(
formRef, formRef,
'focusout', 'focusout',

2
packages/nc-gui/composables/useSharedFormViewStore.ts

@ -81,7 +81,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const route = useRoute() const route = useRoute()
const formState = ref<Record<string, any>>({}) const formState = ref<Record<string, any>>({})
const preFilledformState = ref<Record<string, any>>({}) const preFilledformState = ref<Record<string, any>>({})
const { state: additionalState } = useProvideSmartsheetRowStore( const { state: additionalState } = useProvideSmartsheetRowStore(

Loading…
Cancel
Save