Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

datepicker - bootstrap date picker clear value

I have two dates, Start date and End date. I need to validate the the end date should not greater than the start date.

need to clear (previous start date value) the date value when ever we change the date.

  • case 1# [ First time] start date - 23-Nov-2013 End date - 24-Nov-2013

now i changed the start date as -25-Nov-2013, but end date enabled the the 24-Nov-2013 (start previous value) on wards instead of 26-Nov-203.

So, i need to clear the value when ever i change the date.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Actually, what that 27/11/2013 represents is the current Date. Which will not get updated unless you write it on changeDate event.

So you have to do like

  1. Bind the start date, with changeDate event.
  2. Increment the selected date in start.
  3. Again set back the incremented date.
  4. Now update this to end Date using update method

    $('#end').datepicker('update', toDate);

Finally, you code will be like

$('#start').datepicker({}).on('changeDate', function (ev) {
    var toDate = ev.date;
    toDate.setDate(toDate.getDate() + 1);
    $('#end').datepicker('update', toDate);
});
$('#end').datepicker({});

JSFiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...