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

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

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