Created
March 16, 2019 06:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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