hilongjw / vue-datepicker

[Deprecated] calendar and datepicker component with material design for Vue.js
http://hilongjw.github.io/vue-datepicker/demo.html
MIT License
702 stars 207 forks source link

How to make the limit dynamically? #73

Open JackieLs opened 7 years ago

JackieLs commented 7 years ago

I have a demand: a startTime && a endTime ,when startTime picked the endTime should not > the startTime, off course if endTime picked the startTime should not < the endTime , How Should I do?.....when I declare @change function to return false the value in the input also changed....

geekgirlcoding commented 7 years ago

I created two versions of the "limit" - one called "startLimit" and the other called "endLimit":

startLimit: [{
          type:'fromto',
          from: new Date().setFullYear(new Date().getFullYear - 1),
          to: new Date().setFullYear(new Date().getFullYear + 1),
        }],
        endLimit: [{
          type:'fromto',
          from: new Date().setFullYear(new Date().getFullYear - 1),
          to: new Date().setFullYear(new Date().getFullYear + 1),
        }],

I then created a method that is called when the start_date field is changed:


 checkEndDate(){
        var e = this;
        // If end date is earlier than start date, change end date to start date
        if(e.event_end.time < e.event_start.time){
          e.event_end.time = e.event_start.time;
        }
        e.endLimit[0].from = (e.event_start.time != '' ? new Date(e.event_start.time) : new Date().setFullYear(new Date().getFullYear - 1));
      }
liuestc commented 7 years ago

@JackieLs 如何解决? @geekgirlcoding
I also encountered the same demand, but according to your method and did not take effect, you can look at your code in more detail?