PluginProbe
The Innovative Form Builder – IvyForms / 0.4
The Innovative Form Builder – IvyForms v0.4
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / utils / addFieldUtil.ts

addFieldUtil.ts in The Innovative Form Builder – IvyForms 0.4, at frontend/src/utils/addFieldUtil.ts

49 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import type { Field } from '@/types/field'
2 import { parentChildFieldConfigs } from './parentChildFieldTemplates'
3
4 export function buildNewField(
5 fieldData: Partial<Field> & { type: string },
6 index: number,
7 getLabel: (key: string) => string,
8 ): Field {
9 const config = parentChildFieldConfigs[fieldData.type]
10 if (config) {
11 // Parent-child field type
12 const subFields = config.buildSubFields(getLabel)
13 return {
14 ...(fieldData as Field),
15 id: fieldData.id ?? 0,
16 formId: fieldData.formId ?? 0,
17 fieldIndex: index,
18 type: config.type,
19 label: fieldData.label ?? getLabel(config.type),
20 defaultValue: '',
21 value: '',
22 required: false,
23 [config.subFieldKey]: subFields,
24 limitMaxLength: fieldData.limitMaxLength || false,
25 maxLength: fieldData.maxLength || 255,
26 labelPosition: fieldData.labelPosition || 'top',
27 noDuplicates: fieldData.noDuplicates || false,
28 } as Field
29 }
30 // Regular field type
31 return {
32 ...(fieldData as Field),
33 id: fieldData.id ?? 0,
34 formId: fieldData.formId ?? 0,
35 fieldIndex: index,
36 defaultValue: '',
37 value: '',
38 required: false,
39 limitMaxLength: fieldData.limitMaxLength || false,
40 maxLength: fieldData.maxLength || 255,
41 labelPosition: fieldData.labelPosition || 'top',
42 noDuplicates: fieldData.noDuplicates || false,
43 confirmFieldEnabled: fieldData.confirmFieldEnabled || false,
44 confirmFieldLabel: '',
45 confirmFieldPlaceholder: '',
46 confirmFieldHideLabel: fieldData.confirmFieldEnabled || false,
47 }
48 }
49