Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Created November 14, 2019 03:00
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 bayareawebpro/fb4a6558dd0ad682844ea02bffa70ff1 to your computer and use it in GitHub Desktop.
Save bayareawebpro/fb4a6558dd0ad682844ea02bffa70ff1 to your computer and use it in GitHub Desktop.
<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