mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-22 18:30:36 +03:00
feat: ignore whitespace around separator on manual range input (#416)
This commit is contained in:
@@ -355,8 +355,8 @@ describe('DatePicker', () => {
|
|||||||
|
|
||||||
it('should emit pick event on first click', () => {
|
it('should emit pick event on first click', () => {
|
||||||
wrapper = mount(DatePicker, {
|
wrapper = mount(DatePicker, {
|
||||||
range: true,
|
|
||||||
propsData: {
|
propsData: {
|
||||||
|
range: true,
|
||||||
open: true,
|
open: true,
|
||||||
defaultValue: new Date(2019, 9, 1),
|
defaultValue: new Date(2019, 9, 1),
|
||||||
},
|
},
|
||||||
@@ -365,4 +365,23 @@ describe('DatePicker', () => {
|
|||||||
td.trigger('click');
|
td.trigger('click');
|
||||||
expect(wrapper.emitted().pick[0][0]).toEqual(new Date(2019, 8, 29));
|
expect(wrapper.emitted().pick[0][0]).toEqual(new Date(2019, 8, 29));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Ignore whitespace around separator on manual range input', () => {
|
||||||
|
const rangeSeparator = ' ~ ';
|
||||||
|
const text = '2020-02-12';
|
||||||
|
wrapper = mount(DatePicker, {
|
||||||
|
propsData: {
|
||||||
|
range: true,
|
||||||
|
rangeSeparator: ' ~ ',
|
||||||
|
valueType: 'format',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
|
||||||
|
input.setValue(`${text} ${rangeSeparator} ${text}`);
|
||||||
|
input.trigger('change');
|
||||||
|
input.setValue(`${text}${rangeSeparator.trim()}${text}`);
|
||||||
|
input.trigger('change');
|
||||||
|
expect(wrapper.emitted().input).toEqual([[[text, text]], [[text, text]]]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -419,14 +419,14 @@ export default {
|
|||||||
},
|
},
|
||||||
handleInputChange() {
|
handleInputChange() {
|
||||||
if (!this.editable || this.userInput === null) return;
|
if (!this.editable || this.userInput === null) return;
|
||||||
const text = this.userInput;
|
const text = this.userInput.trim();
|
||||||
this.userInput = null;
|
this.userInput = null;
|
||||||
if (text === '') {
|
if (text === '') {
|
||||||
this.handleClear();
|
this.handleClear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const date = this.range
|
const date = this.range
|
||||||
? text.split(this.rangeSeparator).map(v => this.parseDate(v, this.format))
|
? text.split(this.rangeSeparator.trim()).map(v => this.parseDate(v.trim(), this.format))
|
||||||
: this.parseDate(text, this.format);
|
: this.parseDate(text, this.format);
|
||||||
if (this.isValidValue(date)) {
|
if (this.isValidValue(date)) {
|
||||||
this.emitValue(date);
|
this.emitValue(date);
|
||||||
|
|||||||
Reference in New Issue
Block a user