mirror of
https://github.com/nocodb/nocodb.git
synced 2026-05-01 09:36:51 +00:00
20 lines
533 B
TypeScript
20 lines
533 B
TypeScript
export const deepReferenceHelper = (formState: Ref, path: string): any => {
|
|
return path.split('.').reduce((acc, key) => (acc ? acc[key] : null), formState.value)
|
|
}
|
|
|
|
export const setFormStateHelper = (formState: Ref, path: string, value: any) => {
|
|
// update nested prop in formState
|
|
const keys = path.split('.')
|
|
const lastKey = keys.pop()
|
|
|
|
if (!lastKey) return
|
|
|
|
const target = keys.reduce((acc, key) => {
|
|
if (!acc[key]) {
|
|
acc[key] = {}
|
|
}
|
|
return acc[key]
|
|
}, formState.value)
|
|
target[lastKey] = value
|
|
}
|