Commit 4863a75d921275e5c35f09777d55335ac610aabb
1 parent
77e43f2b
Correct logic when manually inputing disabledDates
Showing
2 changed files
with
21 additions
and
19 deletions
Show diff stats
src/components/date-picker/picker.vue
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | <div ref="reference" :class="[prefixCls + '-rel']"> | 3 | <div ref="reference" :class="[prefixCls + '-rel']"> |
| 4 | <slot> | 4 | <slot> |
| 5 | <i-input | 5 | <i-input |
| 6 | + :key="forceInputRerender" | ||
| 6 | :element-id="elementId" | 7 | :element-id="elementId" |
| 7 | :class="[prefixCls + '-editor']" | 8 | :class="[prefixCls + '-editor']" |
| 8 | :readonly="!editable || readonly" | 9 | :readonly="!editable || readonly" |
| @@ -264,6 +265,10 @@ | @@ -264,6 +265,10 @@ | ||
| 264 | return val === '' || val === null || !isNaN(date.getTime()); | 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 | data(){ | 274 | data(){ |
| @@ -274,7 +279,8 @@ | @@ -274,7 +279,8 @@ | ||
| 274 | internalValue: this.parseDate(this.value), | 279 | internalValue: this.parseDate(this.value), |
| 275 | disableClickOutSide: false, // fixed when click a date,trigger clickoutside to close picker | 280 | disableClickOutSide: false, // fixed when click a date,trigger clickoutside to close picker |
| 276 | disableCloseUnderTransfer: false, // transfer 模式下,点击Drop也会触发关闭, | 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 | computed: { | 286 | computed: { |
| @@ -287,7 +293,6 @@ | @@ -287,7 +293,6 @@ | ||
| 287 | return (isRange || this.multiple) ? val : val[0]; | 293 | return (isRange || this.multiple) ? val : val[0]; |
| 288 | } | 294 | } |
| 289 | }, | 295 | }, |
| 290 | - | ||
| 291 | opened () { | 296 | opened () { |
| 292 | return this.open === null ? this.visible : this.open; | 297 | return this.open === null ? this.visible : this.open; |
| 293 | }, | 298 | }, |
| @@ -341,12 +346,21 @@ | @@ -341,12 +346,21 @@ | ||
| 341 | this.visible = false; | 346 | this.visible = false; |
| 342 | }, | 347 | }, |
| 343 | handleInputChange (event) { | 348 | handleInputChange (event) { |
| 349 | + const isArrayValue = this.type.includes('range') || this.multiple; | ||
| 344 | const oldValue = this.visualValue; | 350 | const oldValue = this.visualValue; |
| 345 | const newValue = event.target.value; | 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 | this.emitChange(); | 360 | this.emitChange(); |
| 349 | - this.internalValue = this.parseDate(newValue); | 361 | + this.internalValue = newDate; |
| 362 | + } else { | ||
| 363 | + this.forceInputRerender++; | ||
| 350 | } | 364 | } |
| 351 | }, | 365 | }, |
| 352 | handleInputMouseenter () { | 366 | handleInputMouseenter () { |
| @@ -393,7 +407,7 @@ | @@ -393,7 +407,7 @@ | ||
| 393 | 407 | ||
| 394 | if (val && type === 'time' && !(val instanceof Date)) { | 408 | if (val && type === 'time' && !(val instanceof Date)) { |
| 395 | val = parser(val, this.format || DEFAULT_FORMATS[type]); | 409 | val = parser(val, this.format || DEFAULT_FORMATS[type]); |
| 396 | - } else if (type.match(/range$/)) { | 410 | + } else if (isRange) { |
| 397 | if (!val){ | 411 | if (!val){ |
| 398 | val = [null, null]; | 412 | val = [null, null]; |
| 399 | } else { | 413 | } else { |
| @@ -403,8 +417,7 @@ | @@ -403,8 +417,7 @@ | ||
| 403 | } else if (typeof val === 'string' && type.indexOf('time') !== 0){ | 417 | } else if (typeof val === 'string' && type.indexOf('time') !== 0){ |
| 404 | val = parser(val, this.format || DEFAULT_FORMATS[type]) || val; | 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 | formatDate(value){ | 422 | formatDate(value){ |
| 410 | const {formatter} = ( | 423 | const {formatter} = ( |
src/components/date-picker/picker/date-picker.js
| @@ -21,18 +21,7 @@ export default { | @@ -21,18 +21,7 @@ export default { | ||
| 21 | return isRange ? 'RangeDatePickerPanel' : 'DatePickerPanel'; | 21 | return isRange ? 'RangeDatePickerPanel' : 'DatePickerPanel'; |
| 22 | }, | 22 | }, |
| 23 | ownPickerProps(){ | 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 | }; |