Commit 939a162ad73c1fe49260941684c2e02c8d63b5c1
1 parent
e9d7ff50
Prevent selecting disabled dates
Showing
4 changed files
with
13 additions
and
4 deletions
Show diff stats
src/components/date-picker/base/date-table.vue
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | </div> | 7 | </div> |
8 | <span | 8 | <span |
9 | :class="getCellCls(cell)" | 9 | :class="getCellCls(cell)" |
10 | - v-for="(cell, i) in readCells" | 10 | + v-for="(cell, i) in cells" |
11 | :key="String(cell.date) + i" | 11 | :key="String(cell.date) + i" |
12 | @click="handleClick(cell, $event)" | 12 | @click="handleClick(cell, $event)" |
13 | @mouseenter="handleMouseMove(cell)" | 13 | @mouseenter="handleMouseMove(cell)" |
@@ -61,7 +61,7 @@ | @@ -61,7 +61,7 @@ | ||
61 | const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay)); | 61 | const weekDays = translatedDays.splice(weekStartDay, 7 - weekStartDay).concat(translatedDays.splice(0, weekStartDay)); |
62 | return this.showWeekNumbers ? [''].concat(weekDays) : weekDays; | 62 | return this.showWeekNumbers ? [''].concat(weekDays) : weekDays; |
63 | }, | 63 | }, |
64 | - readCells () { | 64 | + cells () { |
65 | const tableYear = this.tableDate.getFullYear(); | 65 | const tableYear = this.tableDate.getFullYear(); |
66 | const tableMonth = this.tableDate.getMonth(); | 66 | const tableMonth = this.tableDate.getMonth(); |
67 | const today = clearHours(new Date()); // timestamp of today | 67 | const today = clearHours(new Date()); // timestamp of today |
src/components/date-picker/base/mixin.js
src/components/date-picker/picker.vue
@@ -385,7 +385,15 @@ | @@ -385,7 +385,15 @@ | ||
385 | if (this.type.match(/range/)){ | 385 | if (this.type.match(/range/)){ |
386 | this.$refs.pickerPanel.handleRangePick(this.focusedDate, 'date'); | 386 | this.$refs.pickerPanel.handleRangePick(this.focusedDate, 'date'); |
387 | } else { | 387 | } else { |
388 | - this.onPick(this.focusedDate, false, 'date'); | 388 | + const panels = findComponentsDownward(this, 'PanelTable'); |
389 | + const compareDate = (d) => { | ||
390 | + const sliceIndex = ['year', 'month', 'date'].indexOf((this.type)) + 1; | ||
391 | + return [d.getFullYear(), d.getMonth(), d.getDate()].slice(0, sliceIndex).join('-'); | ||
392 | + }; | ||
393 | + const dateIsValid = panels.find(({cells}) => { | ||
394 | + return cells.find(({date, disabled}) => compareDate(date) === compareDate(this.focusedDate) && !disabled); | ||
395 | + }); | ||
396 | + if (dateIsValid) this.onPick(this.focusedDate, false, 'date'); | ||
389 | } | 397 | } |
390 | } | 398 | } |
391 | 399 |
src/styles/components/date-picker.less