@ -31,7 +31,6 @@ import {
onClickOutside ,
onClickOutside ,
parseProp ,
parseProp ,
provide ,
provide ,
reactive ,
ref ,
ref ,
useDebounceFn ,
useDebounceFn ,
useEventListener ,
useEventListener ,
@ -42,7 +41,7 @@ import {
useRoles ,
useRoles ,
useViewColumnsOrThrow ,
useViewColumnsOrThrow ,
useViewData ,
useViewData ,
watch ,
useViewsStore ,
} from '#imports'
} from '#imports'
import type { ImageCropperConfig } from '~/lib'
import type { ImageCropperConfig } from '~/lib'
@ -72,8 +71,6 @@ const enum NcForm {
const { isMobileMode , user } = useGlobal ( )
const { isMobileMode , user } = useGlobal ( )
const formRef = ref ( )
const { $api , $e } = useNuxtApp ( )
const { $api , $e } = useNuxtApp ( )
const { isUIAllowed } = useRoles ( )
const { isUIAllowed } = useRoles ( )
@ -82,7 +79,9 @@ const { base } = storeToRefs(useBase())
const { getPossibleAttachmentSrc } = useAttachment ( )
const { getPossibleAttachmentSrc } = useAttachment ( )
let formState = reactive < Record < string , any > > ( { } )
const formRef = ref ( )
const formState = ref < Record < string , any > > ( { } )
const secondsRemain = ref ( 0 )
const secondsRemain = ref ( 0 )
@ -98,6 +97,8 @@ const isPublic = inject(IsPublicInj, ref(false))
const { loadFormView , insertRow , formColumnData , formViewData , updateFormView } = useViewData ( meta , view )
const { loadFormView , insertRow , formColumnData , formViewData , updateFormView } = useViewData ( meta , view )
const { preFillFormSearchParams } = storeToRefs ( useViewsStore ( ) )
const reloadEventHook = inject ( ReloadViewDataHookInj , createEventHook ( ) )
const reloadEventHook = inject ( ReloadViewDataHookInj , createEventHook ( ) )
reloadEventHook . on ( async ( ) => {
reloadEventHook . on ( async ( ) => {
@ -110,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 } ,
} ) ,
} ) ,
@ -193,6 +194,22 @@ const updateView = useDebounceFn(
{ maxWait : 2000 } ,
{ maxWait : 2000 } ,
)
)
const updatePreFillFormSearchParams = useDebounceFn ( ( ) => {
if ( isLocked . value || ! isUIAllowed ( 'dataInsert' ) ) return
const preFilledData = { ... formState . value , ... state . value }
const searchParams = new URLSearchParams ( )
for ( const c of visibleColumns . value ) {
if ( c . title && preFilledData [ c . title ] && ! isVirtualCol ( c ) && ! ( UITypes . Attachment === c . uidt ) ) {
searchParams . append ( c . title , preFilledData [ c . title ] )
}
}
preFillFormSearchParams . value = searchParams . toString ( )
} , 250 )
async function submitForm ( ) {
async function submitForm ( ) {
if ( isLocked . value || ! isUIAllowed ( 'dataInsert' ) ) return
if ( isLocked . value || ! isUIAllowed ( 'dataInsert' ) ) return
@ -206,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 } ,
} )
} )
@ -217,9 +234,9 @@ 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 ( )
}
}
@ -321,13 +338,6 @@ async function showOrHideColumn(column: Record<string, any>, show: boolean, isSi
await $api . dbView . formColumnUpdate ( column . id , column )
await $api . dbView . formColumnUpdate ( column . id , column )
fields . value [ fieldIndex ] = column as any
fields . value [ fieldIndex ] = column as any
/ / a w a i t s a v e O r U p d a t e (
/ / {
/ / . . . c o l u m n ,
/ / s h o w ,
/ / } ,
/ / f i e l d I n d e x ,
/ / )
reloadEventHook . trigger ( )
reloadEventHook . trigger ( )
@ -554,6 +564,8 @@ onMounted(async () => {
URL . revokeObjectURL ( imageCropperData . value . imageConfig . src )
URL . revokeObjectURL ( imageCropperData . value . imageConfig . src )
}
}
preFillFormSearchParams . value = ''
isLoadingFormView . value = true
isLoadingFormView . value = true
await loadFormView ( )
await loadFormView ( )
setFormData ( )
setFormData ( )
@ -566,6 +578,7 @@ watch(submitted, (v) => {
const intvl = setInterval ( ( ) => {
const intvl = setInterval ( ( ) => {
if ( -- secondsRemain . value < 0 ) {
if ( -- secondsRemain . value < 0 ) {
submitted . value = false
submitted . value = false
clearForm ( )
clearInterval ( intvl )
clearInterval ( intvl )
}
}
} , 1000 )
} , 1000 )
@ -578,25 +591,35 @@ 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 ) {
document
const field = document . querySelector ( ` .nc-form-field-item- ${ CSS . escape ( newValue ? . replaceAll ( ' ' , '' ) ) } ` )
. querySelector ( ` .nc-form-field-item- ${ newValue ? . replaceAll ( ' ' , '' ) } ` )
? . scrollIntoView ( { behavior : 'smooth' , block : 'center' } )
if ( field ) {
setTimeout ( ( ) => {
field ? . scrollIntoView ( { behavior : 'smooth' , block : 'center' } )
} , 50 )
}
}
}
} )
} )
@ -647,7 +670,7 @@ useEventListener(
( e : KeyboardEvent ) => {
( e : KeyboardEvent ) => {
const cmdOrCtrl = isMac ( ) ? e . metaKey : e . ctrlKey
const cmdOrCtrl = isMac ( ) ? e . metaKey : e . ctrlKey
switch ( e . key . toLowerCase ( ) ) {
switch ( e . key ? . toLowerCase ( ) ) {
case 's' :
case 's' :
if (
if (
cmdOrCtrl &&
cmdOrCtrl &&
@ -736,7 +759,16 @@ useEventListener(
< / div >
< / div >
< div v-if ="formViewData.submit_another_form || !isPublic" class="text-right mt-4" >
< div v-if ="formViewData.submit_another_form || !isPublic" class="text-right mt-4" >
< NcButton type = "primary" size = "medium" @ click = "submitted = false" >
< NcButton
type = "primary"
size = "medium"
@ click = "
( ) => {
submitted = false
clearForm ( )
}
"
>
{ { $t ( 'activity.submitAnotherForm' ) } }
{ { $t ( 'activity.submitAnotherForm' ) } }
< / NcButton >
< / NcButton >
< / div >
< / div >
@ -1056,7 +1088,7 @@ useEventListener(
< / div >
< / div >
<!-- Field Header -- >
<!-- Field Header -- >
< div v-if ="activeRow === element.title" class="w-full flex gap-3 items-center px-3 py-2 bg-gray-50" >
< div v-if ="activeRow === element.title" class="w-full flex gap-3 items-center px-3 py-2 bg-gray-50 border-b-1 border-gray-200 " >
< component
< component
: is = "iconMap.drag"
: is = "iconMap.drag"
class = "nc-form-field-drag-handler flex-none cursor-move !h-4 !w-4 text-gray-600"
class = "nc-form-field-drag-handler flex-none cursor-move !h-4 !w-4 text-gray-600"
@ -1209,7 +1241,7 @@ useEventListener(
<!-- Field Settings -- >
<!-- Field Settings -- >
< div
< div
v - if = "activeRow === element.title && isSelectTypeCol(element.uidt)"
v - if = "activeRow === element.title && isSelectTypeCol(element.uidt)"
class = "nc-form-field-settings border-t border-gray-200 p-4 lg:p-6 flex flex-col gap-3"
class = "nc-form-field-settings border-t border-gray-200 p-4 lg:p-6 flex flex-col gap-3 bg-gray-50 "
>
>
<!-- Layout -- >
<!-- Layout -- >
< div v-if ="isSelectTypeCol(element.uidt)" >
< div v-if ="isSelectTypeCol(element.uidt)" >
@ -1231,7 +1263,7 @@ useEventListener(
< / div >
< / div >
<!-- Todo : Show on conditions , ... -- >
<!-- Todo : Show on conditions , ... -- >
<!-- eslint - disable vue / no - constant - condition -- >
<!-- eslint - disable vue / no - constant - condition -- >
< div v-if ="false" class="flex items-start gap-3 px-3 py-2 border-1 border-gray-200 rounded-lg" >
< div v-if ="false" class="flex items-start gap-3 px-3 py-2 border-1 border-gray-200 rounded-lg bg-white " >
< a -switch v -e = " [ ' a : form -view : field : show -on -condition ' ] " size = "small" class = "nc-form-switch-focus" / >
< a -switch v -e = " [ ' a : form -view : field : show -on -condition ' ] " size = "small" class = "nc-form-switch-focus" / >
< div >
< div >
< div class = "font-medium text-gray-800" > { { $t ( 'labels.showOnConditions' ) } } < / div >
< div class = "font-medium text-gray-800" > { { $t ( 'labels.showOnConditions' ) } } < / div >
@ -1240,7 +1272,7 @@ useEventListener(
< / div >
< / div >
<!-- Limit options -- >
<!-- Limit options -- >
< div v-if ="isSelectTypeCol(element.uidt)" class="px-3 py-2 border-1 border-gray-200 rounded-lg" >
< div v-if ="isSelectTypeCol(element.uidt)" class="px-3 py-2 border-1 border-gray-200 rounded-lg bg-white " >
< div class = "flex items-center gap-3" >
< div class = "flex items-center gap-3" >
< a -switch
< a -switch
v - model : checked = "element.meta.isLimitOption"
v - model : checked = "element.meta.isLimitOption"
@ -1289,6 +1321,7 @@ useEventListener(
>
>
{ { $t ( 'activity.clearForm' ) } }
{ { $t ( 'activity.clearForm' ) } }
< / NcButton >
< / NcButton >
< NcButton
< NcButton
html - type = "submit"
html - type = "submit"
type = "primary"
type = "primary"
@ -1433,7 +1466,7 @@ useEventListener(
< SmartsheetHeaderCellIcon v -else :column-meta ="field" / >
< SmartsheetHeaderCellIcon v -else :column-meta ="field" / >
< div class = "flex-1 flex items-center justify-start max-w-[calc(100%_-_68px)] mr-4" >
< div class = "flex-1 flex items-center justify-start max-w-[calc(100%_-_68px)] mr-4" >
< div class = "w-full flex items-center" >
< div class = "w-full flex items-center" >
< div class = "ml-1 inline-block max-w-1/2 " >
< div class = "ml-1 inline-flex" : class = "field.label?.trim() ? 'max-w-1/2' : 'max-w-[95%]' " >
< NcTooltip class = "truncate text-sm" :disabled ="drag" show -on -truncate -only >
< NcTooltip class = "truncate text-sm" :disabled ="drag" show -on -truncate -only >
< template # title >
< template # title >
< div class = "text-center" >
< div class = "text-center" >
@ -1792,21 +1825,21 @@ useEventListener(
. nc - form - field - ghost {
. nc - form - field - ghost {
@ apply bg - gray - 50 ;
@ apply bg - gray - 50 ;
}
}
: deep ( . nc - form - input - required + button ) : focus {
: deep ( . nc - form - input - required + button ) : focus - visible {
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
}
}
: deep ( . nc - form - switch - focus ) : focus {
: deep ( . nc - form - switch - focus ) : focus - visible {
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
}
}
. nc - form - field - layout {
. nc - form - field - layout {
@ apply ! flex ! items - center w - full space - x - 3 ;
@ apply ! flex ! items - center w - full space - x - 3 ;
: deep ( . ant - radio - wrapper ) {
: deep ( . ant - radio - wrapper ) {
@ apply border - 1 border - gray - 200 rounded - lg ! py - 2 ! px - 3 basis - full ! mr - 0 ! items - center ;
@ apply border - 1 border - gray - 200 rounded - lg ! py - 2 ! px - 3 basis - full ! mr - 0 ! items - center bg - white ;
. ant - radio {
. ant - radio {
@ apply ! top - 0 ;
@ apply ! top - 0 ;
& : focus - within . ant - radio - inner {
. ant - radio - input : focus - visible + . ant - radio - inner {
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
}
}
}
}
@ -1814,12 +1847,9 @@ useEventListener(
}
}
. nc - form - wrapper {
. nc - form - wrapper {
. ant - switch : focus ,
. ant - switch : focus - visible ,
. ant - switch - checked : focus {
. ant - switch - checked : focus - visible {
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
box - shadow : 0 0 0 2 px # fff , 0 0 0 4 px # 3366 ff ;
& : hover {
box - shadow : none ;
}
}
}
}
}
< / style >
< / style >