Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  15] [ 7]  / answers: 1 / hits: 28907  / 11 Years ago, wed, january 29, 2014, 12:00:00

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 Website for Datepicker Library). I made it work with date selectors, but I'm having trouble disabling choosing the past times for arrival field, when the departure time is set.



For example, if the Departure time is set to be 1 March, when the user clicks on the Arrival field in the calendar that pops up, all the dates before 2nd March should be disabled.



I tried multiple versions of code given on demo website, but they didn't work. I think the problem might be that I have jQuery in noConflict mode.



My current script is located in footer.php of my theme. The calendar pop up works, and it disables past dates, but it doesn't disable dates before the Arrival field once the Departure date is set.



This was the most successful attempt, as at least the calendar popups were working on this attempt: http://jsfiddle.net/j5ZKc/



And this is my current script:



<script type=text/javascript>
jQuery(function() {
jQuery('#dp1, #dp2'
).datepicker({startDate: '-0m'}).on('changeDate', function(){
jQuery( '#dp1, #dp2'
).datepicker('hide');
})
});
</script>


Any suggestions please?


More From » jquery

 Answers
17

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();

[#72861] Tuesday, January 28, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lidialyrick

Total Points: 737
Total Questions: 104
Total Answers: 89

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
lidialyrick questions
;