longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

How to just add classs for sunday not to disable? #426

Closed kripikentang12 closed 6 years ago

kripikentang12 commented 6 years ago

Hi,

Can i add class for sunday? i want to change date color to red for sunday, but not disable it.

Thank you

holtkamp commented 6 years ago

This can be done with the beforeShowDay(date) callback, from the documentation:

beforeShowDay (Function)
    A function that takes a date as a parameter and must return an array with:
    [0]: true/false indicating whether or not this date is selectable
    [1]: a CSS class name to add to the date's cell or "" for the default presentation
    [2]: an optional popup tooltip for this date
    The function is called for each day in the datepicker before it is displayed.

so for Sundays, you can return an array like [true, 'cssClassThatIsForSundays']

kripikentang12 commented 6 years ago

Hi @holtkamp,

Thanks for your answer, i have made it like this but it doesn't work. This is my script

<style>
      .markholiday{
             color: red
      }
</style>

 $('#date_search').dateRangePicker({
                separator : ' - ',
                format: 'MM/DD/YYYY',
                autoClose: true,
                startDate: dateToday,
                endDate: endDate,
                beforeShowDay: function (date) {
                            var day = date.getDay();
                            if (day == 0){
                                return [true, 'markholiday']
                            } else{
                                var formattedDate = jQuery.datepicker.formatDate('mm/dd/yy', date);
                                return [true, (holidays.indexOf(formattedDate) == -1) ? '' : 'markholiday'];
                            }
                        }
            });`
holtkamp commented 6 years ago

mm, seems ok, can you provide a working example on www.JSFiddle.net ?

kripikentang12 commented 6 years ago

this is example https://jsfiddle.net/kun05jpk/5/

holtkamp commented 6 years ago

Seems to work: the CSS class is applied properly. You can change your CSS to:

background-color: red; to see this.

kripikentang12 commented 6 years ago

I've tried that but i don't want to change background color, i want to change font color

holtkamp commented 6 years ago

Well, it seems your custom style is overruled by another class

screen shot 2018-04-09 at 11 40 25

You can prevent that using !important, https://css-tricks.com/when-using-important-is-the-right-choice/

    .markholiday{
        color: red !important;
    }
kripikentang12 commented 6 years ago

ok thank you, i got it