Bootstrap Datepicker Disable Past Dates After First Date Field is Set

前端 未结 2 532
醉梦人生
醉梦人生 2021-01-20 20:33

I\'m working on a Wordpress website with the theme based on Bootstrap 3.

In a form I need to include calendar date pickers. I added a js library from eyecon (Demo W

相关标签:
2条回答
  • 2021-01-20 20:40

    Try this code snippet:

    $('#changestartdate').datetimepicker({ minDate:new Date() });

    0 讨论(0)
  • 2021-01-20 20:58

    So after some trouble I finally got something working for you:

    jsFiddle Bootstrap-datepicker

    What did I do:

    I used forked Bootstrap-datepicker. It is in my opinion way better documented and easier to use. I got it working so that should count for something. For example I got the date of the respective datepicker by invoking getDate() on a datepicker:

    checkout.datepicker("getDate").valueOf()
    

    If you have any questions about my code, let me know!

    EDIT:

    I updated the former jsFiddle (see the link above). It automatically sets the value of #dp2 to the selected date of #dp1 + one day. Therefore you should always be in the correct month.

    If you don't want the code to put the focus on #dp2 after a date is selected just remove the following line in the jsFiddle:

    $('#dp2')[0].focus();
    
    0 讨论(0)
提交回复
热议问题