Add min and max range values to date selector so a more accurate error message can be displayed when a date is out of the range
This commit is contained in:
@@ -250,4 +250,33 @@ describe('DateSelector', () => {
|
||||
expect(component.maxError).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('outsideRange', () => {
|
||||
it('should return true if the date is before the minrange', () => {
|
||||
component.minrange = '2020-01-01'
|
||||
component.maxrange = '2025-01-01'
|
||||
component.day = 1
|
||||
component.month = 1
|
||||
component.year = 2005
|
||||
expect(component.outsideRange).toEqual(true)
|
||||
})
|
||||
|
||||
it('should return true if the date is after the maxrange', () => {
|
||||
component.minrange = '2020-01-01'
|
||||
component.maxrange = '2025-01-01'
|
||||
component.day = 1
|
||||
component.month = 1
|
||||
component.year = 2030
|
||||
expect(component.outsideRange).toEqual(true)
|
||||
})
|
||||
|
||||
it('should return false if the date is betwen minrange and maxrange', () => {
|
||||
component.minrange = '2020-01-01'
|
||||
component.maxrange = '2025-01-01'
|
||||
component.day = 1
|
||||
component.month = 1
|
||||
component.year = 2022
|
||||
expect(component.outsideRange).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -19,6 +19,8 @@ export default {
|
||||
initialyear: { type: String },
|
||||
mindate: { type: String },
|
||||
maxdate: { type: String },
|
||||
minrange: { type: String },
|
||||
maxrange: { type: String },
|
||||
nameTag: { type: String },
|
||||
optional: {
|
||||
type: Boolean,
|
||||
@@ -179,6 +181,15 @@ export default {
|
||||
return false
|
||||
},
|
||||
|
||||
outsideRange: function() {
|
||||
if (!!this.maxrange && !!this.minrange && this.isDateComplete) {
|
||||
return (
|
||||
this.dateParsed < this.minRangeParsed ||
|
||||
this.dateParsed > this.maxRangeParsed
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
maxDateParsed: function() {
|
||||
return new Date(this.maxdate)
|
||||
},
|
||||
@@ -187,6 +198,14 @@ export default {
|
||||
return new Date(this.mindate)
|
||||
},
|
||||
|
||||
maxRangeParsed: function() {
|
||||
return new Date(this.maxrange)
|
||||
},
|
||||
|
||||
minRangeParsed: function() {
|
||||
return new Date(this.minrange)
|
||||
},
|
||||
|
||||
dateParsed: function() {
|
||||
return new Date(this.formattedDate)
|
||||
},
|
||||
|
@@ -332,6 +332,8 @@
|
||||
<date-selector
|
||||
:mindate="initialMinStartDate"
|
||||
:maxdate="maxStartProp"
|
||||
:minrange='initialMinStartDate'
|
||||
:maxrange='initialMaxEndDate'
|
||||
|
||||
name-tag='start_date'
|
||||
initialmonth=""
|
||||
@@ -352,10 +354,13 @@
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
|
||||
<div v-if='outsideRange && !minError' class="usa-input-error-message">
|
||||
PoP start date must be before or on September 14, 2022.
|
||||
</div>
|
||||
<div v-if='minError' class="usa-input-error-message">
|
||||
PoP start date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div v-if='maxError' class="usa-input-error-message">
|
||||
<div v-if='maxError && !outsideRange' class="usa-input-error-message">
|
||||
PoP start date must be before end date.
|
||||
</div>
|
||||
</legend>
|
||||
@@ -431,6 +436,8 @@
|
||||
<date-selector
|
||||
:mindate="minEndProp"
|
||||
:maxdate="initialMaxEndDate"
|
||||
:minrange='initialMinStartDate'
|
||||
:maxrange='initialMaxEndDate'
|
||||
|
||||
name-tag='end_date'
|
||||
initialmonth=""
|
||||
@@ -473,11 +480,14 @@
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
|
||||
<div v-if='minError' class="usa-input-error-message">
|
||||
<div v-if='outsideRange && !maxError' class="usa-input-error-message">
|
||||
PoP end date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div v-if='minError && !outsideRange' class="usa-input-error-message">
|
||||
PoP end date must be after start date.
|
||||
</div>
|
||||
<div v-if='maxError' class="usa-input-error-message">
|
||||
PoP end date must be on or after September 14, 2022.
|
||||
PoP end date must be before or on September 14, 2022.
|
||||
</div>
|
||||
</legend>
|
||||
|
||||
|
@@ -19,6 +19,8 @@
|
||||
<date-selector
|
||||
:mindate="initialMinStartDate"
|
||||
:maxdate="maxStartProp"
|
||||
:minrange='initialMinStartDate'
|
||||
:maxrange='initialMaxEndDate'
|
||||
|
||||
name-tag='start_date'
|
||||
initialmonth=""
|
||||
@@ -39,10 +41,13 @@
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
|
||||
<div v-if='outsideRange && !minError' class="usa-input-error-message">
|
||||
PoP start date must be before or on September 14, 2022.
|
||||
</div>
|
||||
<div v-if='minError' class="usa-input-error-message">
|
||||
PoP start date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div v-if='maxError' class="usa-input-error-message">
|
||||
<div v-if='maxError && !outsideRange' class="usa-input-error-message">
|
||||
PoP start date must be before end date.
|
||||
</div>
|
||||
</legend>
|
||||
@@ -118,6 +123,8 @@
|
||||
<date-selector
|
||||
:mindate="minEndProp"
|
||||
:maxdate="initialMaxEndDate"
|
||||
:minrange='initialMinStartDate'
|
||||
:maxrange='initialMaxEndDate'
|
||||
|
||||
name-tag='end_date'
|
||||
initialmonth=""
|
||||
@@ -160,11 +167,14 @@
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
|
||||
<div v-if='minError' class="usa-input-error-message">
|
||||
<div v-if='outsideRange && !maxError' class="usa-input-error-message">
|
||||
PoP end date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div v-if='minError && !outsideRange' class="usa-input-error-message">
|
||||
PoP end date must be after start date.
|
||||
</div>
|
||||
<div v-if='maxError' class="usa-input-error-message">
|
||||
PoP end date must be on or after September 14, 2022.
|
||||
PoP end date must be before or on September 14, 2022.
|
||||
</div>
|
||||
</legend>
|
||||
|
||||
|
@@ -203,7 +203,7 @@
|
||||
<div>
|
||||
<div class="form-row">
|
||||
<div class="form-col">
|
||||
<date-selector :maxdate="maxStartProp" :mindate="initialMinStartDate" :name-tag="'clins-' + clinIndex + '-start_date'" :optional="false" inline-template="" v-on:date-change="handleDateChange">
|
||||
<date-selector :maxdate="maxStartProp" :maxrange="initialMaxEndDate" :mindate="initialMinStartDate" :minrange="initialMinStartDate" :name-tag="'clins-' + clinIndex + '-start_date'" :optional="false" inline-template="" v-on:date-change="handleDateChange">
|
||||
<fieldset :name="name" class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid && isDateComplete, 'usa-input--error': !isDateValid && isDateComplete }">
|
||||
<legend>
|
||||
<div class="usa-input__title">
|
||||
@@ -212,10 +212,13 @@
|
||||
<p class="usa-input__help">
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
<div class="usa-input-error-message" v-if="outsideRange && !minError">
|
||||
PoP start date must be before or on September 14, 2022.
|
||||
</div>
|
||||
<div class="usa-input-error-message" v-if="minError">
|
||||
PoP start date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div class="usa-input-error-message" v-if="maxError">
|
||||
<div class="usa-input-error-message" v-if="maxError && !outsideRange">
|
||||
PoP start date must be before end date.
|
||||
</div>
|
||||
</legend>
|
||||
@@ -251,7 +254,7 @@
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-col">
|
||||
<date-selector :maxdate="initialMaxEndDate" :mindate="minEndProp" :name-tag="'clins-' + clinIndex + '-end_date'" :optional="false" inline-template="" v-on:date-change="handleDateChange">
|
||||
<date-selector :maxdate="initialMaxEndDate" :maxrange="initialMaxEndDate" :mindate="minEndProp" :minrange="initialMinStartDate" :name-tag="'clins-' + clinIndex + '-end_date'" :optional="false" inline-template="" v-on:date-change="handleDateChange">
|
||||
<fieldset :name="name" class="usa-input date-picker" v-bind:class="{ 'usa-input--success': isDateValid && isDateComplete, 'usa-input--error': !isDateValid && isDateComplete }">
|
||||
<legend>
|
||||
<div class="usa-input__title">
|
||||
@@ -267,11 +270,14 @@
|
||||
<p class="usa-input__help">
|
||||
For example: 07 04 1776
|
||||
</p>
|
||||
<div class="usa-input-error-message" v-if="minError">
|
||||
<div class="usa-input-error-message" v-if="outsideRange && !maxError">
|
||||
PoP end date must be on or after September 14, 2019.
|
||||
</div>
|
||||
<div class="usa-input-error-message" v-if="minError && !outsideRange">
|
||||
PoP end date must be after start date.
|
||||
</div>
|
||||
<div class="usa-input-error-message" v-if="maxError">
|
||||
PoP end date must be on or after September 14, 2022.
|
||||
PoP end date must be before or on September 14, 2022.
|
||||
</div>
|
||||
</legend>
|
||||
<div class="date-picker-component">
|
||||
|
Reference in New Issue
Block a user