Answer the question
In order to leave comments, you need to log in
How to prevent negative numbers from being entered?
How to prevent negative numbers from being entered? There is an input field, it displays the number of product positions, there are + and -, which increase or decrease this number. But you can also enter a number and it should not be negative.
span(@click="product.quantity = Math.max(0, product.quantity - 1)" class="minus") −
input(v-model.number="product.quantity" style="display: inline-block")
span(@click="product.quantity++" class="plus") +
Answer the question
In order to leave comments, you need to log in
@input="onInput($event, product)"
methods: {
onInput(e, product) {
product.quantity = Math.max(0, parseInt(e.target.value) || 0);
},
},
watch: {
products: {
deep: true,
handler() {
this.products.forEach(n => n.quantity = Math.max(0, parseInt(n.quantity) || 0));
},
},
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question