Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

259
Vistas
The :max doesn't work properly in html input control when typing in a value

I have a form with inputs based on a model in vue.js. The model contains an array of objects in searchResultOrderLines.

<tr v-for="(item, index) in searchResultOrderLines" v-bind:value="item" v-on:click="editSearchRow(index)">
    <td>
        <input class="form-control" type="number" v-model="item.QuantityPicked" min="0" :max="item.QuantityNeeded" />
    </td>

The input renders as a numeric control with arrows to increment and decrement. It will not allow the user to spin below 0, nor above the value defined in the item.QuantityNeeded, which is as required. However, the user is able to enter a numeric value which is > item.QuantityNeeded, by simply typing into the text box. Is there any way of limiting or preventing this?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

One solution is to apply an input-event handler that resets the <input>'s v-model variable to <input>.max if the value exceeds the max:

<script setup>
let searchResultOrderLines = $ref([
  {
    QuantityNeeded: 10,
    QuantityPicked: 1,
  },
  {
    QuantityNeeded: 100,
    QuantityPicked: 50,
  },
])
         👇
const limitValue = (e, item) => {
  if (Number(e.target.value) > Number(e.target.max)) {
    item.QuantityPicked = Number(e.target.max)
  }
}
</script>

<template>
  <fieldset v-for="item in searchResultOrderLines">
    <input
      class="form-control"
      type="number"
      v-model="item.QuantityPicked"
      min="0"
      :max="item.QuantityNeeded"
      @input="limitValue($event, item)" 👈
    />
  </fieldset>
</template>

demo

about 4 years ago · Juan Pablo Isaza Denunciar

0

A colleague showed me this which also works:

<input v-on:blur="checkQuantity(item, index)" class="form-control" type="number" v-model="item.QuantityPicked" min="0" :max="item.QuantityNeeded" />

checkQuantity: function (item, index) {
    var self = this;
    if (item.QuantityPicked > item.QuantityNeeded) {
        var copyOfItem = Object.assign({}, item);
        copyOfItem.QuantityPicked = item.QuantityNeeded;
        self.$set(self.searchResultOrderLines, index, copyOfItem);
    }
},
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda