PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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 1.0, at frontend/src/views/public/fields/TextFormField.vue

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