jQuery Datepicker how to highlight all dates between ui-datepicker-current-day and another currently hovered date?

user1014412

The jQuery UI datepicker widget automatically adds a class ui-state-hover to a date when hovering it. But how can i configure to add this class to every date between the element having class ui-datepicker-current-day and the currently hovered element having class ui-state-hover?

Dekel

This indeed was a tricky one :)
The problem we got here is that there isn't a callback for afterShow in the datepicker. I found a solution here and did some enhancements:

    function initDatePickerMarkup(e) {
    $(e)
        .datepicker('widget').find('td').mouseover(function() {
            currentDate = new Date($(this).attr('data-year')+"/"+(parseInt($(this).attr('data-month'))+1)+"/"+$(this).text());
            selectedDate = $(e).datepicker('getDate');
            if (selectedDate === null) {
                selectedDate = new Date();
            }
            allTds = $(this).parents('table.ui-datepicker-calendar').find('td');
            allTds.removeClass('ui-datepicker-mouseover1')
            found = false;
            if (currentDate < selectedDate) {
                for (i = 0; i < allTds.length; i++) {
                    if (allTds[i] == this) {
                        found = true;
                    }
                    if ($(allTds[i]).hasClass('ui-datepicker-today') || $(allTds[i]).hasClass('ui-datepicker-current-day')) {
                        break;
                    }
                    if (found) {
                        $(allTds[i]).addClass('ui-datepicker-mouseover1');
                    }
                }
            } else if (currentDate > selectedDate) {
                for (i = 0; i < allTds.length; i++) {
                    if (found) {
                        $(allTds[i]).addClass('ui-datepicker-mouseover1');
                    }
                    if ($(allTds[i]).hasClass('ui-datepicker-today') || $(allTds[i]).hasClass('ui-datepicker-current-day')) {
                        found = true;
                    }
                    if (allTds[i] == this) {
                        break;
                    }
                }
            }
        });
}
$(function() {
    $.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
    $.datepicker._updateDatepicker = function(inst) {
        $.datepicker._updateDatepicker_original(inst);
        var afterShow = this._get(inst, 'afterShow');
        if (afterShow) {
            afterShow.apply((inst.input ? inst.input[0] : null));  // trigger custom callback
        }
    }
    $( "#datepicker" ).datepicker({
        afterShow: function(e) {
            initDatePickerMarkup(this);
        }
    });
});
.ui-datepicker-mouseover1 {
    border: 1px solid red !important;
}
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>datepicker demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<input id="datepicker" />
</body>
</html>

Hope it helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to highlight dates with jQuery's datepicker

From Dev

How to add a day from current date in Jquery Datepicker

From Dev

Disable JQuery datepicker dates by picking a date from another datepicker

From Dev

how to disable all dates except Wednesday and Sunday dates in Jquery Ui Datepicker

From Dev

Disable date before current date in JQuery UI datepicker

From Dev

jQuery UI datepicker highlighting dates

From Dev

How to show a date format in Jquery ui datepicker?

From Dev

Highlight custom dates in datepicker

From Dev

Change the default date of the current inline jQuery UI datepicker

From Dev

Highlight, Disable specific days in jQuery UI datepicker

From Dev

Highlight, Disable specific days in jQuery UI datepicker

From Dev

Date format Datepicker jQuery ui

From Dev

Jquery UI datepicker date format

From Dev

in angular-ui-bootstrap (v.0.10.0) Datepicker - how do i disable single day(s) by date (or array of dates)?

From Dev

JQuery UI Datepicker reinitiate when a change has occurred with another date

From Dev

jQuery UI Datepicker disable all days before certain date

From Dev

How to disable dates in jQuery datepicker?

From Dev

How do I get the difference between 2 dates? jquery datepicker

From Dev

How to list all dates in a month from jquery datepicker?

From Dev

How to list all dates in a month from jquery datepicker?

From Dev

Show current day in the title of jquery datepicker

From Dev

jquery datepicker calendar how to disable sunday date or any day?

From Dev

jQuery UI Datepicker range select for three dates

From Dev

future dates raise error jquery ui datepicker

From Dev

jquery ui datepicker allows past dates?

From Dev

Jquery Datepicker : Never show the day selection "ui-datepicker-calendar"

From Dev

Select next and previous day with jQuery UI datepicker

From Dev

start day of the year in jquery ui datepicker

From Dev

jQuery datepicker hide dates in between two months

Related Related

  1. 1

    How to highlight dates with jQuery's datepicker

  2. 2

    How to add a day from current date in Jquery Datepicker

  3. 3

    Disable JQuery datepicker dates by picking a date from another datepicker

  4. 4

    how to disable all dates except Wednesday and Sunday dates in Jquery Ui Datepicker

  5. 5

    Disable date before current date in JQuery UI datepicker

  6. 6

    jQuery UI datepicker highlighting dates

  7. 7

    How to show a date format in Jquery ui datepicker?

  8. 8

    Highlight custom dates in datepicker

  9. 9

    Change the default date of the current inline jQuery UI datepicker

  10. 10

    Highlight, Disable specific days in jQuery UI datepicker

  11. 11

    Highlight, Disable specific days in jQuery UI datepicker

  12. 12

    Date format Datepicker jQuery ui

  13. 13

    Jquery UI datepicker date format

  14. 14

    in angular-ui-bootstrap (v.0.10.0) Datepicker - how do i disable single day(s) by date (or array of dates)?

  15. 15

    JQuery UI Datepicker reinitiate when a change has occurred with another date

  16. 16

    jQuery UI Datepicker disable all days before certain date

  17. 17

    How to disable dates in jQuery datepicker?

  18. 18

    How do I get the difference between 2 dates? jquery datepicker

  19. 19

    How to list all dates in a month from jquery datepicker?

  20. 20

    How to list all dates in a month from jquery datepicker?

  21. 21

    Show current day in the title of jquery datepicker

  22. 22

    jquery datepicker calendar how to disable sunday date or any day?

  23. 23

    jQuery UI Datepicker range select for three dates

  24. 24

    future dates raise error jquery ui datepicker

  25. 25

    jquery ui datepicker allows past dates?

  26. 26

    Jquery Datepicker : Never show the day selection "ui-datepicker-calendar"

  27. 27

    Select next and previous day with jQuery UI datepicker

  28. 28

    start day of the year in jquery ui datepicker

  29. 29

    jQuery datepicker hide dates in between two months

HotTag

Archive