Current constraint of min
and max
are not respected due to the way v-on
is implemented:
<input id="passwordLength"
class="form-control form-control-sm"
type="number"
min="5"
max="35"
v-model="options.length">
<span class="input-group-btn" v-on:click="options.length+=1">
<button class="btn btn-secondary" type="button">
<i class="fa fa-plus"></i>
</button>
</span>
Question
How can I respect the constrain and still keep an elegant implementation?
Use @Focus to apply a max & min number validation to your :rules. Make sure to set the max with large default number. Both max & min default will be updated upon focusing on that specific input box. (This text-fields are being created with a loop)
I did something basic:
Usage
Service Tests
Service Code
You could add a custom modifier to the
v-model
directive:Then, all you would need to do is add a
.range
modifier tov-model
when you want the model to respect themin
andmax
attributes of the affected element:Here's a CodePen Example.
Here's Vue's (semi-lacking) documentation on directives.