Only update the min and max values for other field when the field that was updated is valid -- This prevents both fields from becoming invalid when the dates are not in chronological order.

This commit is contained in:
leigh-mil 2019-09-23 16:52:05 -04:00
parent d42cd1ff4f
commit d52abeb0a9

View File

@ -21,13 +21,20 @@ export default {
}, },
data: function() { data: function() {
var start = new Date(this.initialStartDate)
var end = new Date(this.initialEndDate)
var contractStart = new Date(this.initialMinStartDate)
var contractEnd = new Date(this.initialMaxEndDate)
return { return {
startDate: new Date(this.initialStartDate), startDate: start,
endDate: new Date(this.initialEndDate), endDate: end,
startValid: false, startValid: false,
endValid: false, endValid: false,
minStartDate: new Date(this.initialMinStartDate), maxStartDate: this.calcMaxStartDate(end, contractEnd),
maxEndDate: new Date(this.initialMaxEndDate), minEndDate: this.calcMinEndDate(start, contractStart),
contractStart: contractStart,
contractEnd: contractEnd,
} }
}, },
@ -40,36 +47,40 @@ export default {
if (event.name.includes(START_DATE)) { if (event.name.includes(START_DATE)) {
if (!!event.value) this.startDate = new Date(event.value) if (!!event.value) this.startDate = new Date(event.value)
if (!!event.valid) this.startValid = event.valid if (!!event.valid) this.startValid = event.valid
if (this.startValid)
this.minEndDate = this.calcMinEndDate(this.startDate)
} else if (event.name.includes(END_DATE)) { } else if (event.name.includes(END_DATE)) {
if (!!event.value) this.endDate = new Date(event.value) if (!!event.value) this.endDate = new Date(event.value)
if (!!event.valid) this.endValid = event.valid if (!!event.valid) this.endValid = event.valid
if (this.endValid)
this.maxStartDate = this.calcMaxStartDate(this.endDate)
} }
}, },
maxStartDate: function() { calcMaxStartDate: function(date, end = this.contractEnd) {
if (this.endDate < new Date(this.initialMaxEndDate)) { if (date < end) {
return this.endDate return date
} else { } else {
return this.initialMaxEndDate return end
} }
}, },
minEndDate: function() { calcMinEndDate: function(date, start = this.contractStart) {
if (this.startDate > new Date(this.initialMinStartDate)) { if (date > start) {
return this.startDate return date
} else { } else {
return this.initialMinEndDate return start
} }
}, },
}, },
computed: { computed: {
maxStartProp: function() { maxStartProp: function() {
return format(this.maxStartDate(), 'YYYY-MM-DD') return format(this.maxStartDate, 'YYYY-MM-DD')
}, },
minEndProp: function() { minEndProp: function() {
return format(this.minEndDate(), 'YYYY-MM-DD') return format(this.minEndDate, 'YYYY-MM-DD')
} },
} },
} }