Skip to content

Instantly share code, notes, and snippets.

@rslhdyt
Created March 16, 2019 06:11
Show Gist options
  • Save rslhdyt/dc0edde9ba79c19d9b875ef533ed9369 to your computer and use it in GitHub Desktop.
Save rslhdyt/dc0edde9ba79c19d9b875ef533ed9369 to your computer and use it in GitHub Desktop.
[Form Group Component] Vuejs form group component wrapper using bootstrap-vue and vee-validate #vuejs #validation #bootstrap
<template>
<ValidationProvider :rules="rules" :name="$attrs.label">
<b-form-group slot-scope="{ valid, errors }" :label="$attrs.label" :invalid-feedback="errors[0]">
<b-input
:state="errors[0] ? false : (valid ? true : null)"
:name="$attrs.label.toLowerCase()"
:type="$attrs.type"
:placeholder="$attrs.placeholder"
v-model="innerValue" />
</b-form-group>
</ValidationProvider>
</template>
<script>
import { ValidationProvider } from 'vee-validate'
export default {
props: [
'rules',
'value'
],
components: {
ValidationProvider
},
data: () => ({
innerValue: ''
}),
watch: {
// Handles internal model changes.
innerValue (newVal) {
this.$emit('input', newVal)
},
// Handles external model changes.
value (newVal) {
this.innerValue = newVal
}
},
created () {
if (this.value) {
this.innerValue = this.value
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment