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

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

116 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__number',
5 'ivyforms-field__number_' + 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 <IvyTextNumberInput
21 :id="fieldID"
22 v-model="localModelValue"
23 class="ivyforms-field__number-input"
24 :placeholder="field.placeholder"
25 :disabled="disabled"
26 :readonly="props.field.readOnly"
27 :required="field.required"
28 :step="field.step && field.step > 0 ? field.step : 1"
29 :number-format="field.numberFormat || ''"
30 />
31 </IvyFormItem>
32 </div>
33 </template>
34
35 <script setup lang="ts">
36 import { computed, inject } from 'vue'
37 import IvyTextNumberInput from '@/views/_components/input/IvyTextNumberInput.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 // Added optional numeric input configuration
52 step?: number
53 numberFormat?: 'us_decimal' | 'us_int' | 'eu_decimal' | 'eu_int' | ''
54 labelPosition?: string
55 noDuplicates?: boolean
56 // Any other field properties from your data
57 }
58 interface FieldProps {
59 modelValue: string | number | null | undefined
60 field: Field
61 disabled?: boolean
62 error?: string
63 }
64
65 const props = withDefaults(defineProps<FieldProps>(), {
66 modelValue: '',
67 disabled: false,
68 error: '',
69 })
70
71 const emit = defineEmits(['update:modelValue'])
72
73 // Inject clearFieldError function from parent
74 const clearFieldError = inject<(fieldKey: string) => void>('clearFieldError', () => {})
75
76 // Generate field key for clearing errors
77 const fieldKey = computed(() => {
78 return props.field.type + '_' + props.field.fieldIndex
79 })
80
81 // Handle input event to clear errors when user starts typing
82 const handleInput = (value: string | number | null | undefined) => {
83 emit('update:modelValue', value === undefined || value === null ? '' : value)
84 clearFieldError(fieldKey.value)
85 }
86
87 const localModelValue = computed({
88 get() {
89 const val = props.modelValue
90 if (val === '' || val === null || val === undefined || isNaN(Number(val))) return undefined
91 return typeof val === 'number' ? val : Number(val)
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__number-input_${props.field.formId || ''}_${props.field.fieldIndex || ''}`
100 })
101 </script>
102
103 <style scoped lang="scss">
104 .ivyforms-field__number {
105 &.is-readonly {
106 :deep(.el-input__wrapper),
107 :deep(.el-input__wrapper:hover),
108 :deep(.el-input__wrapper.is-focus),
109 :deep(.el-input__inner) {
110 cursor: not-allowed;
111 pointer-events: none;
112 }
113 }
114 }
115 </style>
116