PluginProbe
The Innovative Form Builder – IvyForms / 0.7
The Innovative Form Builder – IvyForms v0.7
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 0.7, at frontend/src/views/public/fields/PhoneFormField.vue

119 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 ]"
8 >
9 <IvyFormItem
10 :label="field.hideLabel ? '' : field.label"
11 :required="field.required"
12 :error="error"
13 :prop="field.type + '_' + field.fieldIndex"
14 :show-info="!!field.description"
15 :info-text="field.description || ''"
16 :label-position="field.labelPosition"
17 :show-info-icon="false"
18 >
19 <IvyPhoneInput
20 :id="fieldID"
21 v-model="localModelValue"
22 class="ivyforms-field__phone-input"
23 :placeholder="field.placeholder"
24 :disabled="disabled || field.readOnly"
25 :readonly="field.readOnly"
26 :required="field.required"
27 :phone-format="field.phoneFormat || 'national'"
28 :auto-detect-country="field.phoneAutoDetect !== false"
29 :aria-label="field.hideLabel ? field.label || 'Phone number' : ''"
30 :aria-labelledby="field.hideLabel ? '' : `ivyforms-label-${fieldID}`"
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 phoneFormat?: 'international' | 'national' | 'e164'
52 phoneAutoDetect?: boolean
53 defaultValue?: string
54 requiredMessage?: string
55 labelPosition?: string
56 noDuplicates?: boolean
57 // Any other field properties from your data
58 }
59 interface FieldProps {
60 modelValue: string | number | null | undefined
61 field: Field
62 disabled?: boolean
63 error?: string
64 }
65
66 const props = withDefaults(defineProps<FieldProps>(), {
67 modelValue: '',
68 disabled: false,
69 error: '',
70 })
71
72 const emit = defineEmits(['update:modelValue'])
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 != null ? String(props.modelValue) : ''
91 },
92 set(value) {
93 handleInput(value)
94 },
95 })
96 // Generate unique field ID as a string
97 const fieldID = computed(() => {
98 return `ivyforms-field__phone-input_${props.field.formId || ''}_${props.field.fieldIndex || ''}`
99 })
100 </script>
101
102 <style scoped lang="scss">
103 .ivyforms-field__phone {
104 &.is-readonly {
105 :deep(.ivyforms-phone-input),
106 :deep(.ivyforms-phone-input:hover),
107 :deep(.ivyforms-phone-input.is-focus) {
108 border-color: var(--map-base-dusk-stroke--2) !important;
109 box-shadow: none !important;
110 }
111 }
112 :deep(.ivyforms-phone-input__arrow) {
113 .ivyforms-icon__svg {
114 width: auto;
115 }
116 }
117 }
118 </style>
119