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 / views / public / fields / TextFormField.vue

TextFormField.vue in The Innovative Form Builder – IvyForms 0.4, at frontend/src/views/public/fields/TextFormField.vue

105 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <template>
2 <div :class="['ivyforms-field__text', 'ivyforms-field__text_' + field.id, field.cssClasses]">
3 <IvyFormItem
4 :label="field.hideLabel ? '' : field.label"
5 :required="field.required"
6 :error="error"
7 :prop="field.type + '_' + field.fieldIndex"
8 :show-info="!!field.description"
9 :info-text="field.description || ''"
10 :show-info-icon="false"
11 :label-position="field.labelPosition"
12 >
13 <IvyTextInput
14 :id="fieldID"
15 v-model="localModelValue"
16 class="ivyforms-field__text-input"
17 type="text"
18 :placeholder="field.placeholder"
19 :disabled="disabled"
20 :readonly="field.readOnly"
21 :required="field.required"
22 :maxlength="field.limitMaxLength ? field.maxLength : undefined"
23 />
24 </IvyFormItem>
25 </div>
26 </template>
27
28 <script setup lang="ts">
29 import { computed, inject } from 'vue'
30
31 interface Field {
32 id: number
33 formId: number
34 fieldIndex: number
35 type: string
36 label: string
37 placeholder?: string
38 required?: boolean
39 hideLabel?: boolean
40 readOnly?: boolean
41 description?: string
42 cssClasses?: string
43 limitMaxLength?: boolean
44 maxLength?: number
45 labelPosition?: string
46 noDuplicates?: boolean
47 // Any other field properties from your data
48 }
49 interface FieldProps {
50 modelValue: string | number | null | undefined
51 field: Field
52 disabled?: boolean
53 error?: string
54 }
55
56 const props = withDefaults(defineProps<FieldProps>(), {
57 modelValue: '',
58 disabled: false,
59 error: '',
60 })
61
62 const emit = defineEmits(['update:modelValue'])
63
64 // Inject clearFieldError function from parent
65 const clearFieldError = inject<(fieldKey: string) => void>('clearFieldError', () => {})
66
67 // Generate field key for clearing errors
68 const fieldKey = computed(() => {
69 return props.field.type + '_' + props.field.fieldIndex
70 })
71
72 // Handle input event to clear errors when user starts typing
73 const handleInput = (value: string | number | null | undefined) => {
74 emit('update:modelValue', value)
75 clearFieldError(fieldKey.value)
76 }
77
78 const localModelValue = computed({
79 get() {
80 return props.modelValue
81 },
82 set(value) {
83 handleInput(value)
84 },
85 })
86
87 // Generate unique field ID as a string
88 const fieldID = computed(() => {
89 return `ivyforms-field__text-input_${props.field.formId || ''}_${props.field.fieldIndex || ''}`
90 })
91 </script>
92
93 <style scoped lang="scss">
94 .ivyforms-field__text {
95 &.is-readonly {
96 :deep(.el-input__wrapper),
97 :deep(.el-input__wrapper:hover),
98 :deep(.el-input__wrapper.is-focus) {
99 border-color: var(--map-base-dusk-stroke--2) !important;
100 box-shadow: none !important;
101 }
102 }
103 }
104 </style>
105