In this code:
<button type="button @click="editing=true">Edit</button>
<form v-show="editing" @submit="onSubmit">
<textarea v-model="text"></textarea>
</form>
<div> Current value: {{text}} </div>
new Vue({ //...
data: {
editing: false,
text: 'initial value..'
}
methods: {
onSubmit: function() { if (this.value.length < 5) alert("error") }
}
}
How can I make sure that {{text}} displays only a validated value? Do I have to create two data members - one for the form and another for display? that will lead to some mess in my code (I have many large forms).
Maybe there is a v-model update hook for validation?
The point of this question - if it's possible to avoid having two data members.
{{text}}when data isn't valid? Last valid value?