From 32583feb991aa5c75abde4e8864cb4520fe477ad Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Tue, 24 Sep 2019 10:51:36 -0400 Subject: [PATCH] Validate year based on min and max dates and only show the validation icons when the date has been completely filled in --- js/components/date_selector.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/js/components/date_selector.js b/js/components/date_selector.js index 646cc6c5..8ca56cb0 100644 --- a/js/components/date_selector.js +++ b/js/components/date_selector.js @@ -102,7 +102,9 @@ export default { isYearValid: function() { // Emit a change event - var valid = parseInt(this.year) >= 1 + var minYear = new Date(this.mindate).getFullYear() + var maxYear = new Date(this.maxdate).getFullYear() + var valid = this.year >= minYear && this.year <= maxYear this._emitChange('year', this.year, valid) return valid }, @@ -135,6 +137,15 @@ export default { ) }, + isDateComplete: function() { + return ( + !!this.day && + !!this.month && + !!this.year && + this.year > 999 + ) + }, + daysMaxCalculation: function() { switch (parseInt(this.month)) { case 2: // February @@ -161,7 +172,7 @@ export default { methods: { onInput: function(e) { - this.showValidation = true + if (this.isDateComplete) this.showValidation = true emitEvent('field-change', this, { value: this.formattedDate,