PluginProbe
The Innovative Form Builder – IvyForms / 0.5
The Innovative Form Builder – IvyForms v0.5
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.5, at frontend/src/utils/addFieldUtil.ts

55 lines 1.8 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 readOnly: false,
24 [config.subFieldKey]: subFields,
25 limitMaxLength: fieldData.limitMaxLength || false,
26 maxLength: fieldData.maxLength || 255,
27 labelPosition: fieldData.labelPosition || 'default',
28 noDuplicates: fieldData.noDuplicates || false,
29 inputPrefix: fieldData.inputPrefix || '',
30 inputSuffix: fieldData.inputSuffix || '',
31 } as Field
32 }
33 // Regular field type
34 return {
35 ...(fieldData as Field),
36 id: fieldData.id ?? 0,
37 formId: fieldData.formId ?? 0,
38 fieldIndex: index,
39 defaultValue: '',
40 value: '',
41 required: false,
42 readOnly: false,
43 limitMaxLength: fieldData.limitMaxLength || false,
44 maxLength: fieldData.maxLength || 255,
45 labelPosition: fieldData.labelPosition || 'default',
46 noDuplicates: fieldData.noDuplicates || false,
47 confirmFieldEnabled: fieldData.confirmFieldEnabled || false,
48 confirmFieldLabel: '',
49 confirmFieldPlaceholder: '',
50 confirmFieldHideLabel: fieldData.confirmFieldEnabled || false,
51 inputPrefix: fieldData.inputPrefix || '',
52 inputSuffix: fieldData.inputSuffix || '',
53 }
54 }
55