Commit 5d1c24c7f400a208504cf19e6e6a00e7d80a4678
1 parent
109465d3
correct behaviour when initialising date-picker with a empty string
Showing
2 changed files
with
29 additions
and
14 deletions
Show diff stats
src/components/date-picker/picker.vue
... | ... | @@ -517,7 +517,7 @@ |
517 | 517 | val = val.join(RANGE_SEPARATOR); |
518 | 518 | val = parser(val, this.format || DEFAULT_FORMATS[type]); |
519 | 519 | } else if (typeof val === 'string' && type.indexOf('time') !== 0 ){ |
520 | - val = parser(val, this.format || DEFAULT_FORMATS[type]); | |
520 | + val = parser(val, this.format || DEFAULT_FORMATS[type]) || val; | |
521 | 521 | } |
522 | 522 | |
523 | 523 | this.internalValue = val; | ... | ... |
test/unit/specs/date-picker.spec.js
... | ... | @@ -103,19 +103,19 @@ describe('DatePicker.vue', () => { |
103 | 103 | |
104 | 104 | vm.dateType = 'year'; |
105 | 105 | promissedTick(picker) |
106 | - .then(() => { | |
107 | - expect(picker.type).to.equal('year'); | |
108 | - expect(picker.selectionMode).to.equal('year'); | |
109 | - | |
110 | - vm.dateType = 'date'; | |
111 | - return promissedTick(picker); | |
112 | - }) | |
113 | - .then(() => { | |
114 | - expect(picker.type).to.equal('date'); | |
115 | - expect(picker.selectionMode).to.equal('day'); | |
116 | - | |
117 | - done(); | |
118 | - }); | |
106 | + .then(() => { | |
107 | + expect(picker.type).to.equal('year'); | |
108 | + expect(picker.selectionMode).to.equal('year'); | |
109 | + | |
110 | + vm.dateType = 'date'; | |
111 | + return promissedTick(picker); | |
112 | + }) | |
113 | + .then(() => { | |
114 | + expect(picker.type).to.equal('date'); | |
115 | + expect(picker.selectionMode).to.equal('day'); | |
116 | + | |
117 | + done(); | |
118 | + }); | |
119 | 119 | }); |
120 | 120 | }); |
121 | 121 | |
... | ... | @@ -176,4 +176,19 @@ describe('DatePicker.vue', () => { |
176 | 176 | }); |
177 | 177 | }); |
178 | 178 | }); |
179 | + | |
180 | + it('should accept a empty string as input v-model value', done => { | |
181 | + vm = createVue({ | |
182 | + template: '<date-picker v-model="value" type="date"></date-picker>', | |
183 | + data(){ | |
184 | + return {value: ''}; | |
185 | + } | |
186 | + }); | |
187 | + | |
188 | + vm.$nextTick(() => { | |
189 | + expect(vm.value).to.equal(''); | |
190 | + done(); | |
191 | + }); | |
192 | + }); | |
193 | + | |
179 | 194 | }); | ... | ... |