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 / PhoneFormField.vue

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

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