Allowed smart inputs to accept errors as props

This commit is contained in:
Stefan Zermatten
2019-02-20 14:27:20 +02:00
parent 97ec5d4b5c
commit 9d027aeabf
4 changed files with 18 additions and 6 deletions

View File

@@ -12,7 +12,7 @@ export default {
inheritAttrs: false, inheritAttrs: false,
data(){ return { data(){ return {
error: false, error: false,
errorMessages: [], ackErrors: null,
focused: false, focused: false,
loading: false, loading: false,
dirty: false, dirty: false,
@@ -25,6 +25,7 @@ export default {
type: Number, type: Number,
default: 750, default: 750,
}, },
errorMessages: [String, Array],
}, },
watch: { watch: {
focused(newFocus){ focused(newFocus){
@@ -56,7 +57,7 @@ export default {
safeValue(newSafeValue){ safeValue(newSafeValue){
// The safe value only gets updated from the parent, so it must be valid // The safe value only gets updated from the parent, so it must be valid
this.error = false; this.error = false;
this.errorMessages = []; this.ackErrors = null;
}, },
}, },
methods: { methods: {
@@ -70,7 +71,7 @@ export default {
this.loading = false; this.loading = false;
this.dirty = false; this.dirty = false;
this.error = !!error; this.error = !!error;
this.errorMessages = error || []; this.ackErrors = error || null;
}, },
change(val){ change(val){
this.dirty = true; this.dirty = true;
@@ -86,6 +87,17 @@ export default {
this.$nextTick(() => this.safeValue = this.value); this.$nextTick(() => this.safeValue = this.value);
}, },
}, },
computed: {
errors(){
let errors = this.ackErrors ? [this.ackErrors] : [];
if (Array.isArray(this.errorMessages)){
errors.push(...this.errorMessages);
} else if (typeof this.errorMessages === 'string' && this.errorMessages){
errors.push(this.errorMessages);
}
return errors;
},
},
created(){ created(){
this.debouncedChange = debounce(this.change, this.debounceTime); this.debouncedChange = debounce(this.change, this.debounceTime);
}, },

View File

@@ -2,7 +2,7 @@
<v-select <v-select
v-bind="$attrs" v-bind="$attrs"
:loading="loading" :loading="loading"
:error-messages="errorMessages" :error-messages="errors"
:value="safeValue" :value="safeValue"
:menu-props="{auto: true, lazy: true}" :menu-props="{auto: true, lazy: true}"
@change="change" @change="change"

View File

@@ -2,7 +2,7 @@
<v-textarea <v-textarea
v-bind="$attrs" v-bind="$attrs"
:loading="loading" :loading="loading"
:error-messages="errorMessages" :error-messages="errors"
:value="safeValue" :value="safeValue"
@input="input" @input="input"
@focus="focused = true" @focus="focused = true"

View File

@@ -2,7 +2,7 @@
<v-text-field <v-text-field
v-bind="$attrs" v-bind="$attrs"
:loading="loading" :loading="loading"
:error-messages="errorMessages" :error-messages="errors"
:value="safeValue" :value="safeValue"
@input="input" @input="input"
@focus="focused = true" @focus="focused = true"