Skip to content

Commit d4e4b05

Browse files
committed
Add min-date and max-date props
1 parent eb004f1 commit d4e4b05

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Vue.extend({
6464
<datetime v-model="date"></datetime>
6565
```
6666

67-
### Full
67+
### Complete
6868

6969
```html
7070
<datetime v-model="date"
@@ -75,6 +75,8 @@ Vue.extend({
7575
placeholder="Select date"
7676
locale="es"
7777
:disabled-dates="['2017-09-07', ['2017-09-25', '2017-10-05']]"
78+
max-date="2017-12-10"
79+
min-date="2017-07-10"
7880
monday-first
7981
auto-continue
8082
auto-close
@@ -85,24 +87,26 @@ Vue.extend({
8587

8688
Parameter | Type | Default
8789
--------- | ---- | ------
88-
v-model (*required*) | `String` | -
90+
v-model (*required*) | Date `String` | -
8991
type | `String`: *date*, *datetime* or *time* | `date`
9092
input-format | `String` | `YYYY-MM-DD`, `YYYY-MM-DD HH:mm` or `HH:mm`
9193
wrapper-class | `String` | `null`
9294
input-class | `String` | `null`
9395
placeholder | `String` | `null`
9496
locale | `String` | `null`
95-
disabled-dates | `Array` | `[]`
97+
disabled-dates | `Array` of date `Strings` | `[]`
98+
min-date | Date `String` | `null`
99+
max-date | Date `String` | `null`
96100
monday-first | `Boolean` | `false`
97101
auto-continue | `Boolean` | `false`
98102
auto-close | `Boolean` | `false`
99103
required | `Boolean` | `false`
100104

101-
The component is based on [Moment.js](https://momentjs.com), check out documentation to set `input-format` and `locale`.
105+
The component is based on [Moment.js](https://momentjs.com), check out documentation to set dates (ISO 8601 recommended), `input-format` and `locale`.
102106

103107
## Events
104108

105-
Component emit the `input` event.
109+
Component emits the `input` event.
106110

107111
# License
108112

src/Datetime.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@
9898
type: String,
9999
default: null
100100
},
101+
minDate: {
102+
type: String,
103+
default: null
104+
},
105+
maxDate: {
106+
type: String,
107+
default: null
108+
},
101109
disabledDates: {
102110
type: Array,
103111
default () {
@@ -207,7 +215,7 @@
207215
}
208216
})
209217
},
210-
disabledDatesParsed () {
218+
disabledDatesRanges () {
211219
return this.disabledDates.map(function (item) {
212220
return Array.isArray(item) ? [moment(item[0]), moment(item[1])] : [moment(item), moment(item).add(1, 'day')]
213221
})
@@ -321,9 +329,11 @@
321329
this.newDate = this.typeFlow.date.clone()
322330
},
323331
isDisabled (date) {
324-
return this.disabledDatesParsed && this.disabledDatesParsed.find(function (dates) {
325-
return date.isBetween(dates[0], dates[1], 'day', '[)')
326-
}) !== undefined
332+
return (this.minDate && date.isBefore(this.minDate, 'day')) ||
333+
(this.maxDate && date.isAfter(this.maxDate, 'day')) ||
334+
(this.disabledDatesRanges && this.disabledDatesRanges.find(function (dates) {
335+
return date.isBetween(dates[0], dates[1], 'day', '[)')
336+
}) !== undefined)
327337
}
328338
}
329339
}

0 commit comments

Comments
 (0)