I need help with two text inputs that are connected v-model to a ref object. I also have two other refs, minimum (100) and maximum(1000). My goal is to allow users to input values within the range of the minimum and maximum values provided. If the value entered falls below the minimum, it should automatically default to 100. Similarly, if the value exceeds the maximum, it should default to 1000.
<input type="text" v-model="number.one" class="one" @input="validate"/>
<input type="text" v-model="number.two" class="two" @input="validate"/>
const min = ref(100)
const max = ref(1000)
const numbers = ref({
one: 100,
two: 100
})
const validate = () => {
if(e.target.className === 'one'){
if(numbers.value.one <= min.value){
numbers.value.one = min.value
}else if(numbers.value.one > max.value){
numbers.value.one = max.value
}
}
}
After implementing this, I encountered an issue where I could no longer input any values in the input field. I suspect this is because numbers.value.one is now equal to the minimum which restricts further modification. How can I overcome this limitation and still be able to update the values?