i have a project using Vue js and Quasar.
I have an input field that is initialized with 10 zeros that only allows numeric numbers.
If I want to add a number, it should fill it in from behind.
"0000000000" -> fill in 1
"0000000001" -> fill in 2
"0000000012" -> fill in 5
"0000000125" -> delete last character
"0000000012" -> fill in 3
"0000000123"
any ideas how i can achieve this? This is what i have currently:
<template>
<div>
<q-input class="input" v-model="number" outlined label="number" mask="##########" minLength="10" maxlength="10" @input="onInput"/>
</div>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const number = ref("0000000000")
}
return {
number
}
}
</script>
onInput does nothing so far
2
Answers
You should use
But it only works well with
maxlength="x"
andmask="#*(x-1)
(mask="#########"
) and does not work withmask="#*x
You can use the function
String.prototype.padStart
to add leading 0 characters until a certain string lenght.Just update the v-model accordingly whenever it changes.
Here is the live demo