vuetify
vuetify copied to clipboard
fix(validation): validate initial input value
Description
closes #15568
this is a change to default behaviour, but I think the old behaviour could be classified as a bug.
Markup:
<template>
<v-form v-model="valid">
<v-text-field autofocus label="name" v-model="name" required :rules="nameRules"></v-text-field>
<v-text-field label="type" v-model="type" required :rules="typeRules"></v-text-field>
</v-form>
Valid: {{ valid === null ? 'null' : valid }}
<v-btn :disabled="!valid">Sa</v-btn>
</template>
<script>
export default {
data () {
return {
valid: false,
name: '',
type: 'asdasdasdasd',
nameRules: [(v) => (!!v && v.length > 5) || "EDITOR.stories.storyNameRequired"],
typeRules: [(v) => !!v || "EDITOR.stories.typeIsRequired"],
}
},
}
</script>
TODO: this has the same issue as optional PR in that empty value is different for different components so just checking if(model.value) is probably not enough
TODO: this has the same issue as optional PR in that empty value is different for different components so just checking if(model.value) is probably not enough
What about a clearFunction property that each component would define?
This should be more similar to v2.
- Inputs should always be validated initially no matter what the value is
- There should be some way to run validation "silently" without displaying errors to the user
- There should be some way to disable the initial validation, for example if async rules are used