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,
data(){ return {
error: false,
errorMessages: [],
ackErrors: null,
focused: false,
loading: false,
dirty: false,
@@ -25,6 +25,7 @@ export default {
type: Number,
default: 750,
},
errorMessages: [String, Array],
},
watch: {
focused(newFocus){
@@ -56,7 +57,7 @@ export default {
safeValue(newSafeValue){
// The safe value only gets updated from the parent, so it must be valid
this.error = false;
this.errorMessages = [];
this.ackErrors = null;
},
},
methods: {
@@ -70,7 +71,7 @@ export default {
this.loading = false;
this.dirty = false;
this.error = !!error;
this.errorMessages = error || [];
this.ackErrors = error || null;
},
change(val){
this.dirty = true;
@@ -86,6 +87,17 @@ export default {
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(){
this.debouncedChange = debounce(this.change, this.debounceTime);
},

View File

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

View File

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

View File

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