mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-23 14:00:35 +03:00
fix: value entered manually in disabled range should be invalid (#508)
This commit is contained in:
@@ -418,4 +418,24 @@ describe('DatePicker', () => {
|
|||||||
});
|
});
|
||||||
expect(vm.validMultipleType).toBe(false);
|
expect(vm.validMultipleType).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('If the value entered manually is in the disabled range should be invalid', () => {
|
||||||
|
const someday = new Date(2020, 6, 1);
|
||||||
|
wrapper = shallowMount(DatePicker, {
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
propsData: {
|
||||||
|
disabledDate: date => {
|
||||||
|
return date < someday;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const textInput = wrapper.find('input');
|
||||||
|
textInput.setValue('2020-08-01');
|
||||||
|
textInput.trigger('change');
|
||||||
|
expect(wrapper.emitted().input[0][0]).toEqual(new Date(2020, 7, 1));
|
||||||
|
textInput.setValue('2020-05-01');
|
||||||
|
textInput.trigger('change');
|
||||||
|
expect(wrapper.emitted().input[1]).toBe(undefined);
|
||||||
|
expect(wrapper.emitted()['input-error'][0][0]).toBe('2020-05-01');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+14
-1
@@ -396,6 +396,19 @@ export default {
|
|||||||
}
|
}
|
||||||
return isValidDate(value);
|
return isValidDate(value);
|
||||||
},
|
},
|
||||||
|
isValidValueAndNotDisabled(value) {
|
||||||
|
if (!this.isValidValue(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const disabledDate =
|
||||||
|
typeof this.disabledDate === 'function' ? this.disabledDate : () => false;
|
||||||
|
const disabledTime =
|
||||||
|
typeof this.disabledTime === 'function' ? this.disabledTime : () => false;
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
value = [value];
|
||||||
|
}
|
||||||
|
return value.every(v => !disabledDate(v) && !disabledTime(v));
|
||||||
|
},
|
||||||
handleMultipleDates(date, dates) {
|
handleMultipleDates(date, dates) {
|
||||||
if (this.validMultipleType && dates) {
|
if (this.validMultipleType && dates) {
|
||||||
const nextDates = dates.filter(v => v.getTime() !== date.getTime());
|
const nextDates = dates.filter(v => v.getTime() !== date.getTime());
|
||||||
@@ -470,7 +483,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
date = this.parseDate(text, this.format);
|
date = this.parseDate(text, this.format);
|
||||||
}
|
}
|
||||||
if (this.isValidValue(date)) {
|
if (this.isValidValueAndNotDisabled(date)) {
|
||||||
this.emitValue(date);
|
this.emitValue(date);
|
||||||
this.blur();
|
this.blur();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user