PluginProbe
The Innovative Form Builder – IvyForms / 0.8.2
The Innovative Form Builder – IvyForms v0.8.2
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 / admin / form-builder / fields / numeric / NumericField.vue

NumericField.vue in The Innovative Form Builder – IvyForms 0.8.2, at frontend/src/views/admin/form-builder/fields/numeric/NumericField.vue

134 lines 3.8 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__numeric">
3 <IvyFormItem
4 :label="hideLabel ? '' : label"
5 :required="required"
6 :label-position="labelPosition"
7 >
8 <IvyTextNumberInput
9 :id="index"
10 read-only
11 :placeholder="placeholder"
12 :model-value="numericModelValue"
13 :number-format="numberFormat"
14 />
15 <div v-if="description" class="ivyforms-description-message regular-14">
16 {{ description }}
17 </div>
18 </IvyFormItem>
19 </div>
20 </template>
21
22 <script setup lang="ts">
23 import { computed } from 'vue'
24 import { useFormBuilder } from '@/stores/useFormBuilder'
25 import IvyTextNumberInput from '@/views/_components/input/IvyTextNumberInput.vue'
26
27 type NumberFormat = 'us_decimal' | 'us_int' | 'eu_decimal' | 'eu_int' | ''
28
29 const VALID_NUMBER_FORMATS: readonly string[] = [
30 'us_decimal',
31 'us_int',
32 'eu_decimal',
33 'eu_int',
34 '',
35 ] as const
36
37 function isNumberFormat(value: string | undefined | null): value is NumberFormat {
38 if (typeof value !== 'string') return false
39 return VALID_NUMBER_FORMATS.includes(value)
40 }
41
42 const props = defineProps<{ fieldIndex: number }>()
43 const formBuilderStore = useFormBuilder()
44
45 // Computed properties to dynamically get values from the store
46 const field = computed(() => formBuilderStore.fields.find((f) => f.fieldIndex === props.fieldIndex))
47
48 const label = computed(() => field.value?.label || '')
49 const placeholder = computed(() => field.value?.placeholder || '')
50 const required = computed(() => field.value?.required || false)
51 const hideLabel = computed(() => field.value?.hideLabel || false)
52 const index = computed(() => field.value?.fieldIndex ?? props.fieldIndex)
53 const numericModelValue = computed(() => {
54 const defaultVal = field.value?.defaultValue
55 if (defaultVal === '' || defaultVal === null || defaultVal === undefined) return null
56 const parsed = Number(defaultVal)
57 return isNaN(parsed) ? null : parsed
58 })
59 const description = computed(() => field.value?.description || '')
60 const labelPosition = computed(() =>
61 field.value?.labelPosition === 'default' ? 'top' : field.value?.labelPosition || 'top',
62 )
63 const numberFormat = computed(() => {
64 const format = field.value?.numberFormat || ''
65 return isNumberFormat(format) ? format : ''
66 })
67 </script>
68
69 <style lang="scss" scoped>
70 .ivyforms-field__numeric {
71 cursor: default;
72 .ivyforms-form-item {
73 margin-bottom: 0;
74 :deep(.ivyforms-form-item__label) {
75 display: flex;
76 align-items: center;
77 color: var(--map-base-text-0);
78 font-size: 14px;
79 font-style: normal;
80 font-weight: 500;
81 line-height: 20px;
82 cursor: default !important;
83 }
84 :deep(.el-form-item__label) {
85 cursor: default;
86 }
87 :deep(.ivyforms-text-number) {
88 cursor: default;
89
90 .ivyforms-text-number__btn {
91 cursor: default;
92 pointer-events: none;
93 }
94
95 .ivyforms-input.el-input {
96 .el-input__wrapper:hover,
97 .el-input__wrapper.is-focus,
98 .el-input__wrapper {
99 border-radius: var(--Radius-radius-md, 8px);
100 border: 1px solid var(--map-base-dusk-stroke--2);
101 background: transparent;
102 box-shadow: none;
103 padding: 0 44px;
104 transition: none;
105 cursor: default;
106 }
107 input {
108 border: none;
109 background: transparent;
110 cursor: default;
111 box-shadow: none;
112 text-align: center;
113
114 &:focus {
115 outline: none;
116 border: 1px solid transparent;
117 background: none;
118 box-shadow: none;
119 }
120 }
121 }
122 }
123 }
124 .ivyforms-description-message {
125 color: var(--map-base-text-0);
126 display: block;
127 width: 100%;
128 white-space: normal;
129 overflow-wrap: anywhere;
130 word-break: break-word;
131 }
132 }
133 </style>
134