Skip to content

Commit cbdde98

Browse files
committed
feat(datepicker): Watch for whether value date is disabled
1 parent 50b2a3d commit cbdde98

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/components/Datepicker.vue

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,21 @@ export default {
379379
openDate() {
380380
this.setPageDate()
381381
},
382-
value(value) {
383-
const parsedValue = this.parseValue(value)
384-
this.setValue(parsedValue)
382+
value: {
383+
handler(newValue, oldValue) {
384+
let parsedValue = this.parseValue(newValue)
385+
const oldParsedValue = this.parseValue(oldValue)
386+
387+
if (!this.utils.compareDates(parsedValue, oldParsedValue)) {
388+
const isDateDisabled = parsedValue && this.isDateDisabled(parsedValue)
389+
390+
if (isDateDisabled) {
391+
parsedValue = null
392+
}
393+
this.setValue(parsedValue)
394+
}
395+
},
396+
immediate: true,
385397
},
386398
view(newView, oldView) {
387399
this.handleViewChange(newView, oldView)
@@ -605,18 +617,7 @@ export default {
605617
/**
606618
* Initiate the component
607619
*/
608-
// eslint-disable-next-line complexity,max-statements
609620
init() {
610-
if (this.value) {
611-
let parsedValue = this.parseValue(this.value)
612-
const isDateDisabled = parsedValue && this.isDateDisabled(parsedValue)
613-
614-
if (isDateDisabled) {
615-
parsedValue = null
616-
}
617-
this.setValue(parsedValue)
618-
}
619-
620621
if (this.typeable) {
621622
this.latestValidTypedDate = this.selectedDate || this.computedOpenDate
622623
}

0 commit comments

Comments
 (0)