Allowed smart inputs to accept errors as props
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<v-textarea
|
||||
v-bind="$attrs"
|
||||
:loading="loading"
|
||||
:error-messages="errorMessages"
|
||||
:error-messages="errors"
|
||||
:value="safeValue"
|
||||
@input="input"
|
||||
@focus="focused = true"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user