From 9d027aeabf834fafdb23558417a2d2b4e54927a0 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 20 Feb 2019 14:27:20 +0200 Subject: [PATCH] Allowed smart inputs to accept errors as props --- app/imports/ui/components/global/SmartInput.js | 18 +++++++++++++++--- .../ui/components/global/SmartSelect.vue | 2 +- app/imports/ui/components/global/TextArea.vue | 2 +- app/imports/ui/components/global/TextField.vue | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/imports/ui/components/global/SmartInput.js b/app/imports/ui/components/global/SmartInput.js index a730533f..e24e402c 100644 --- a/app/imports/ui/components/global/SmartInput.js +++ b/app/imports/ui/components/global/SmartInput.js @@ -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); }, diff --git a/app/imports/ui/components/global/SmartSelect.vue b/app/imports/ui/components/global/SmartSelect.vue index 3c96442b..c11ab3b1 100644 --- a/app/imports/ui/components/global/SmartSelect.vue +++ b/app/imports/ui/components/global/SmartSelect.vue @@ -2,7 +2,7 @@