Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datepicker initial view date when opened #94

Closed
dragospeta opened this issue May 8, 2018 · 3 comments
Closed

Datepicker initial view date when opened #94

dragospeta opened this issue May 8, 2018 · 3 comments

Comments

@dragospeta
Copy link

The date picker view is always opened at the present date or the model value date.

In my use case i have the last 18 years disabled and the user has to go 18 years behind so that he can select a date. A workaround is to initialize the date with the maximum valid date but if the input is empty it will open at the present date.

Could we have a prop that tells the component at what date the view should open?

@mengxiong10
Copy link
Owner

mengxiong10 commented May 8, 2018

No one prop can customize it.
But you can change the methods like this.

import DatePicker from 'vue2-datepicker'

DatePicker.components.CalendarPanel.methods.updateNow = function () {
  this.now = this.value
              ? new Date(this.value)
              : new Date('2017-01-01') // when the value is empty, default is new Date()
}

@dragospeta
Copy link
Author

dragospeta commented May 9, 2018

Thanks, it works! For those who need it put this code in main.js and use view-date="2017-01-01" prop where you need it in the datepicker component.

DatePicker.props.viewDate = {
  type: String,
  default: function () {
    return null
  }
}
DatePicker.components.CalendarPanel.methods.updateNow = function () {
  var viewDate = this.$parent.$props.viewDate

  if (this.value) this.now = new Date(this.value)
  else if (viewDate) this.now = new Date(viewDate)
  else this.now = new Date()
}

@mengxiong10
Copy link
Owner

mengxiong10 commented Feb 12, 2019

v2.10.0 Add the prop default-value to implement it

<date-picker v-model="value" default-value="2020-01-01" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants