Skip to content

Commit f7383c9

Browse files
authored
Merge pull request #468 from devforth/feature/AdminForth/1179/fix-afcl-input
fix: enhance input handling with min/max validation and refactor inpu…
2 parents 0cad44d + 796e6a4 commit f7383c9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

adminforth/spa/src/afcl/Input.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
ref="input"
1313
v-bind="$attrs"
1414
:type="type"
15-
@input="$emit('update:modelValue', type === 'number' ? Number(($event.target as HTMLInputElement)?.value) : ($event.target as HTMLInputElement)?.value)"
15+
:min="min"
16+
:max="max"
17+
@input="onInput"
1618
:value="modelValue"
1719
aria-describedby="helper-text-explanation"
1820
class="afcl-input inline-flex bg-lightInputBackground text-lightInputText dark:text-darkInputText border border-lightInputBorder rounded-0 focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary
@@ -48,8 +50,31 @@ const props = defineProps<{
4850
suffix?: string,
4951
prefix?: string,
5052
readonly?: boolean,
53+
min?: number | null,
54+
max?: number | null,
5155
}>()
5256
57+
const emit = defineEmits<{
58+
(e: 'update:modelValue', value: number | null): void
59+
}>();
60+
61+
const onInput = (e: Event) => {
62+
const el = e.target as HTMLInputElement;
63+
64+
if (props.type === 'number') {
65+
let val = Number(el.value);
66+
67+
if (props.min != null && val < props.min) val = props.min;
68+
if (props.max != null && val > props.max) val = props.max;
69+
70+
el.value = String(val);
71+
emit('update:modelValue', val);
72+
} else {
73+
emit('update:modelValue', el.value);
74+
}
75+
};
76+
77+
5378
const input = ref<HTMLInputElement | null>(null)
5479
5580
defineExpose({

0 commit comments

Comments
 (0)