From f3de41cc06174c4570a22035b306946dd771b5a0 Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Fri, 2 Aug 2019 15:15:32 -0400 Subject: [PATCH] Fix issue where error message was showing up before both dates were filled in - only set startDate and endDate in data if there is are initial dates - only update popValid and showPopError if both dates are present --- js/components/clin_fields.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/js/components/clin_fields.js b/js/components/clin_fields.js index b18cd3fd..b00666fa 100644 --- a/js/components/clin_fields.js +++ b/js/components/clin_fields.js @@ -42,8 +42,12 @@ export default { data: function() { const loas = this.initialLoaCount == 0 ? 1 : 0 const indexOffset = this.initialLoaCount - const start = new Date(this.initialStartDate) - const end = new Date(this.initialEndDate) + const start = !!this.initialStartDate + ? new Date(this.initialStartDate) + : undefined + const end = !!this.initialEndDate + ? new Date(this.initialEndDate) + : undefined const popValidation = !this.initialStartDate ? false : start < end const showPopValidation = !this.initialStartDate ? false : !popValidation @@ -99,8 +103,12 @@ export default { }, validatePop: function() { - this.popValid = this.checkPopValid() - this.showPopError = !this.popValid + if (!!this.startDate && !!this.endDate) { + // only want to update popValid and showPopError if both dates are filled in + this.popValid = this.checkPopValid() + this.showPopError = !this.popValid + } + emitEvent('field-change', this, { name: POP, valid: this.checkPopValid(), @@ -116,10 +124,10 @@ export default { this.amount = parseFloat(event.value) this.clinChangeEvent() } else if (event.name.includes(START_DATE)) { - this.startDate = new Date(event.value) + if (!!event.value) this.startDate = new Date(event.value) this.validatePop() } else if (event.name.includes(END_DATE)) { - this.endDate = new Date(event.value) + if (!!event.value) this.endDate = new Date(event.value) this.validatePop() } }