From bbc02ad4a31a7b2b712c8cd3b7b80d08d26cd307 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Mon, 19 Sep 2022 14:23:27 +0530 Subject: [PATCH] refactor: move field evaluations to Base.vue - minor style updates --- src/components/Controls/Base.vue | 35 ++++++++++++++++++++++++---- src/components/Controls/Currency.vue | 4 ++++ src/components/Controls/Date.vue | 8 ++----- src/components/Controls/TableRow.vue | 4 +--- src/components/TwoColumnForm.vue | 7 +----- src/pages/Report.vue | 2 +- src/utils/doc.ts | 22 ++++++++++------- 7 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/components/Controls/Base.vue b/src/components/Controls/Base.vue index b9e241cb..cd5348ee 100644 --- a/src/components/Controls/Base.vue +++ b/src/components/Controls/Base.vue @@ -6,6 +6,7 @@ import { isNumeric } from 'src/utils'; +import { evaluateReadOnly, evaluateRequired } from 'src/utils/doc'; +import { getIsNullOrUndef } from 'utils/index'; export default { name: 'Base', @@ -33,8 +36,9 @@ export default { placeholder: String, size: String, showLabel: Boolean, - readOnly: Boolean, autofocus: Boolean, + readOnly: { type: [null, Boolean], default: null }, + required: { type: [null, Boolean], default: null }, }, emits: ['focus', 'input', 'change'], inject: { @@ -93,7 +97,7 @@ export default { containerClasses() { /** * Used to accomodate extending compoents where the input is contained in - * a div eg * AutoComplete + * a div eg AutoComplete */ const classes = ['rounded']; if (!this.isReadOnly) { @@ -101,7 +105,7 @@ export default { } if (this.border) { - classes.push('bg-gray-50'); + classes.push('bg-gray-50 border border-gray-200'); } return classes; @@ -109,12 +113,33 @@ export default { inputPlaceholder() { return this.placeholder || this.df.placeholder || this.df.label; }, + showMandatory() { + return this.isEmpty && this.isRequired; + }, + isEmpty() { + if (typeof this.value === 'string' && !this.value) { + return true; + } + + if (getIsNullOrUndef(this.value)) { + return true; + } + + return false; + }, isReadOnly() { - if (this.readOnly != null) { + if (typeof this.readOnly === 'boolean') { return this.readOnly; } - return this.df.readOnly; + return evaluateReadOnly(this.df, this.doc); + }, + isRequired() { + if (typeof this.required === 'boolean') { + return this.required; + } + + return evaluateRequired(this.df, this.doc); }, }, methods: { diff --git a/src/components/Controls/Currency.vue b/src/components/Controls/Currency.vue index 6f0c724c..06a2d7d0 100644 --- a/src/components/Controls/Currency.vue +++ b/src/components/Controls/Currency.vue @@ -63,6 +63,10 @@ export default { this.triggerChange(value); }, activateInput() { + if (this.isReadOnly) { + return; + } + this.showInput = true; nextTick(() => { this.focus(); diff --git a/src/components/Controls/Date.vue b/src/components/Controls/Date.vue index 58ee6598..52599a1b 100644 --- a/src/components/Controls/Date.vue +++ b/src/components/Controls/Date.vue @@ -1,16 +1,12 @@