Refactor filters and input validation

This commit is contained in:
kur0nek-o
2024-03-01 15:08:42 +07:00
parent c1b4443906
commit 91e01ca8de
5 changed files with 201 additions and 112 deletions

View File

@@ -1,4 +1,6 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
const props = defineProps({
placeholder: {
type: String,
@@ -29,12 +31,23 @@ const handleBlur = (e: any) => {
const handleFocus = (e: any) => {
e.target.value = e.target.value.replace(/[^0-9.]/g, '')
}
const emit = defineEmits(['update:text'])
const text = ref(props.value)
watch(text, (val) => {
const validatedText = val.replace(/[^0-9.]/g, '')
if (parseInt(validatedText)) {
emit('update:text', validatedText)
}
})
</script>
<template>
<div class="relative w-full overflow-hidden rounded-lg bg-gray-200">
<input
:value="props.value"
v-model="text"
autocomplete="off"
type="text"
:placeholder="placeholder"