Skip to content

Instantly share code, notes, and snippets.

@carvalhoviniciusluiz
Created March 21, 2019 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carvalhoviniciusluiz/bf3db74edb4b69bebb766ad46135ac7e to your computer and use it in GitHub Desktop.
Save carvalhoviniciusluiz/bf3db74edb4b69bebb766ad46135ac7e to your computer and use it in GitHub Desktop.
e.g validate
<template>
<v-form ref="form" v-model="valid" lazy-validation>
<v-flex xs12>
<v-text-field
:rules="[rules.required]"
label="Firstname"
v-model="firstname"
@update:error='doSomething'
required
></v-text-field>
</v-flex>
<v-btn
:disabled="!valid"
color="success"
@click="validate"
>
Submit
</v-btn>
</v-form>
</template>
<script>
export default {
data () {
return {
valid: true,
firstname: '',
rules: {
required: v => !!v || 'Field is required.'
}
}
},
methods: {
doSomething (error) {
console.log({ error })
},
validate () {
if (this.$refs.form.validate()) {
console.log('submited!!')
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment