Commit 4863a75d921275e5c35f09777d55335ac610aabb

Authored by Sergio Crisostomo
1 parent 77e43f2b

Correct logic when manually inputing disabledDates

src/components/date-picker/picker.vue
... ... @@ -3,6 +3,7 @@
3 3 <div ref="reference" :class="[prefixCls + '-rel']">
4 4 <slot>
5 5 <i-input
  6 + :key="forceInputRerender"
6 7 :element-id="elementId"
7 8 :class="[prefixCls + '-editor']"
8 9 :readonly="!editable || readonly"
... ... @@ -264,6 +265,10 @@
264 265 return val === '' || val === null || !isNaN(date.getTime());
265 266 }
266 267 }
  268 + },
  269 + options: {
  270 + type: Object,
  271 + default: () => ({})
267 272 }
268 273 },
269 274 data(){
... ... @@ -274,7 +279,8 @@
274 279 internalValue: this.parseDate(this.value),
275 280 disableClickOutSide: false, // fixed when click a date,trigger clickoutside to close picker
276 281 disableCloseUnderTransfer: false, // transfer 模式下,点击Drop也会触发关闭,
277   - selectionMode: this.onSelectionModeChange(this.type)
  282 + selectionMode: this.onSelectionModeChange(this.type),
  283 + forceInputRerender: 1
278 284 };
279 285 },
280 286 computed: {
... ... @@ -287,7 +293,6 @@
287 293 return (isRange || this.multiple) ? val : val[0];
288 294 }
289 295 },
290   -
291 296 opened () {
292 297 return this.open === null ? this.visible : this.open;
293 298 },
... ... @@ -341,12 +346,21 @@
341 346 this.visible = false;
342 347 },
343 348 handleInputChange (event) {
  349 + const isArrayValue = this.type.includes('range') || this.multiple;
344 350 const oldValue = this.visualValue;
345 351 const newValue = event.target.value;
  352 + const newDate = this.parseDate(newValue);
  353 + const disabledDateFn =
  354 + this.options &&
  355 + typeof this.options.disabledDate === 'function' &&
  356 + this.options.disabledDate;
  357 + const valueToTest = isArrayValue ? newDate : newDate[0];
346 358  
347   - if (newValue !== oldValue) {
  359 + if (newValue !== oldValue && !disabledDateFn(valueToTest)) {
348 360 this.emitChange();
349   - this.internalValue = this.parseDate(newValue);
  361 + this.internalValue = newDate;
  362 + } else {
  363 + this.forceInputRerender++;
350 364 }
351 365 },
352 366 handleInputMouseenter () {
... ... @@ -393,7 +407,7 @@
393 407  
394 408 if (val && type === 'time' && !(val instanceof Date)) {
395 409 val = parser(val, this.format || DEFAULT_FORMATS[type]);
396   - } else if (type.match(/range$/)) {
  410 + } else if (isRange) {
397 411 if (!val){
398 412 val = [null, null];
399 413 } else {
... ... @@ -403,8 +417,7 @@
403 417 } else if (typeof val === 'string' && type.indexOf('time') !== 0){
404 418 val = parser(val, this.format || DEFAULT_FORMATS[type]) || val;
405 419 }
406   -
407   - return isRange ? val : [val];
  420 + return (isRange || this.multiple) ? val : [val];
408 421 },
409 422 formatDate(value){
410 423 const {formatter} = (
... ...
src/components/date-picker/picker/date-picker.js
... ... @@ -21,18 +21,7 @@ export default {
21 21 return isRange ? 'RangeDatePickerPanel' : 'DatePickerPanel';
22 22 },
23 23 ownPickerProps(){
24   - return {};
  24 + return this.options;
25 25 }
26 26 },
27   -/*
28   - created () {
29   - if (!this.currentValue) {
30   - if (this.type === 'daterange' || this.type === 'datetimerange') {
31   - this.currentValue = ['',''];
32   - } else {
33   - this.currentValue = '';
34   - }
35   - }
36   - }
37   -*/
38 27 };
... ...