diff --git a/js/components/__tests__/date_selector.test.js b/js/components/__tests__/date_selector.test.js index 70125c9d..8820ea41 100644 --- a/js/components/__tests__/date_selector.test.js +++ b/js/components/__tests__/date_selector.test.js @@ -214,4 +214,40 @@ describe('DateSelector', () => { expect(component.isDateComplete).toEqual(false) }) }) + + describe('minError', () => { + it('returns true if the date is before mindate', () => { + component.mindate = new Date("2020-01-01") + component.day = 1 + component.month = 1 + component.year = 2000 + expect(component.minError).toEqual(true) + }) + + it('returns fals if the date is after mindate', () => { + component.mindate = new Date("2020-01-01") + component.day = 1 + component.month = 1 + component.year = 2025 + expect(component.minError).toEqual(false) + }) + }) + + describe('maxError', () => { + it('returns true if the date is after maxdate', () => { + component.maxdate = new Date("2020-01-01") + component.day = 1 + component.month = 1 + component.year = 2025 + expect(component.maxError).toEqual(true) + }) + + it('returns false if the date is before maxdate', () => { + component.maxdate = new Date("2020-01-01") + component.day = 1 + component.month = 1 + component.year = 2005 + expect(component.maxError).toEqual(false) + }) + }) }) diff --git a/js/components/date_selector.js b/js/components/date_selector.js index 0398de49..b11a856e 100644 --- a/js/components/date_selector.js +++ b/js/components/date_selector.js @@ -170,6 +170,22 @@ export default { return 31 } }, + + minError: function() { + if (this.isDateComplete) { + return new Date(this.mindate) > new Date(this.formattedDate) + } + + return false + }, + + maxError: function() { + if (this.isDateComplete) { + return new Date(this.maxdate) < new Date(this.formattedDate) + } + + return false + }, }, methods: { diff --git a/templates/components/clin_fields.html b/templates/components/clin_fields.html index b6db59f3..88b1b478 100644 --- a/templates/components/clin_fields.html +++ b/templates/components/clin_fields.html @@ -135,11 +135,6 @@ {% else %} {{ PopDateRange(watch=True, optional=False, mindate=contract_start | dateFromString(formatter="%Y-%m-%d"), maxdate=contract_end | dateFromString(formatter="%Y-%m-%d")) }} {% endif %} -
-
-

-
-
diff --git a/templates/components/pop_date_range.html b/templates/components/pop_date_range.html index bdc32830..a7f18ba3 100644 --- a/templates/components/pop_date_range.html +++ b/templates/components/pop_date_range.html @@ -41,6 +41,13 @@

{{ "task_orders.form.pop_example" | translate | safe }}

+ +
+ PoP start date must be on or after {{ mindate | formattedDate(formatter="%B %d, %Y") }}. +
+
+ PoP start date must be before end date. +
@@ -130,6 +137,13 @@

{{ 'task_orders.form.pop_example' | translate }}

+ +
+ PoP end date must be after start date. +
+
+ PoP end date must be on or after {{ maxdate | formattedDate(formatter="%B %d, %Y") }}. +