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

Single month shows previous month on selection #343

Closed ARehmanMahi closed 2 years ago

ARehmanMahi commented 7 years ago

Single month mode.

Selecting would show March instead of April for selection as the current month is April.

This happens when enddate is defined. How to set it to use current month?

$('#single_date_range').dateRangePicker(
{
    singleMonth: true,
    showShortcuts: true,
    showTopbar: true,
    separator: ' - ',
    format: 'YYYY-MM-DD',
    startOfWeek: 'monday',
    endDate: moment().format('YYYY-MM-DD'),
    setValue: function(s,s1,s2)
    {
        $('#single_date_range').val(s);
        $('#single_date_start').val(s1);
        $('#single_date_end').val(s2);
    },

    customShortcuts:
    [
        {
            name: 'Clear',
            dates : resetDateRange
        }
    ]
});
holtkamp commented 7 years ago

Can you provide a working example of your issue using https://jsfiddle.net ?

ARehmanMahi commented 7 years ago

@holtkamp

Here's The JSfiddle

ARehmanMahi commented 7 years ago

@holtkamp Hi, Did you got time to saw the fiddle? Any hope for this?

holtkamp commented 7 years ago

Hi @bsienn, thanks for the Fiddle, had a look and it seems the combination of endMonth and singleMonth: true do not work well.

When using singleMonth: false, the last month IS the current month (in this case: April). So the mechanism that determines which month is the last, should take into account that only one month is displayed.

singleMonth: true

screen shot 2017-04-19 at 09 45 20

singleMonth: false

screen shot 2017-04-19 at 09 44 05

So the source of the problem is known. Only the solution is more difficult... For the time being, you could use singleMonth: false as a workaround. Note that on small/mobile devices this will not work. Personally I do not have time to dive into this...

ARehmanMahi commented 7 years ago

Alright, Thanks for your time. I'm just a mid level developer, I tried to find a solution bus wasn't able to. I'll wait or even try again some time soon again because I love this plugin and use this feature.

ARehmanMahi commented 7 years ago

For a workaround I have added the following line to force jump to next month after Init code.

$('.date-picker-wrapper').find('span.next').click();