Created
November 14, 2019 03:00
-
-
Save bayareawebpro/fb4a6558dd0ad682844ea02bffa70ff1 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
/** | |
* @property validator | |
**/ | |
export default { | |
name: "Control", | |
props: { | |
field: { | |
type: String, | |
}, | |
type: { | |
type: String, | |
}, | |
label: { | |
type: String, | |
}, | |
help: { | |
type: String, | |
}, | |
}, | |
inject: [ | |
'form', | |
'validator', | |
], | |
computed: { | |
isInvalid() { | |
return this.validator.has(this.field) | |
}, | |
error() { | |
return this.validator.first(this.field) | |
} | |
}, | |
} | |
</script> | |
<template> | |
<div class="element"> | |
<label :for="field" class="label"> | |
{{ label }} | |
</label> | |
<textarea | |
v-if="type === 'textarea'" | |
:name="field" | |
v-model="form[field]" | |
class="input" | |
:class="{invalid: isInvalid}" | |
@input="validator.forget(field)"> | |
</textarea> | |
<input | |
v-else | |
:name="field" | |
:type="type" | |
v-model="form[field]" | |
class="input" | |
:class="{invalid: isInvalid}" | |
@input="validator.forget(field)" | |
/> | |
<p class="help" :class="{invalid: isInvalid}"> | |
{{ error || help }} | |
</p> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment