Editor datepicker min/max problem

Editor datepicker min/max problem

borconiborconi Posts: 56Questions: 19Answers: 1

Hi Allan.

I think I have found a bug in the recent Editor, here is the description/problem:

The followng lines evaluates if the maxDate is higher or not then next month, and then it uses this to display/hide next month button. The problem is that if we do not set a maxdate in option, maxdate is null which means it will always evaluate to true and you never see a next month button. Even Editors Example page suffer from this.

    var overMax = maxDate < new Date( Date.UTC(year, month+1, 1, 0, 0, 0 ) );

    this.dom.title.find('div.'+classPrefix+'-iconLeft')
        .css( 'display', underMin ? 'none' : 'block' );

    this.dom.title.find('div.'+classPrefix+'-iconRight')
        .css( 'display', overMax ? 'none' : 'block' );

I have quickly fixed it like this:

    var overMax = maxDate < new Date( Date.UTC(year, month+1, 1, 0, 0, 0 ) );
        if (maxDate === null)
            overMax=false;

A second problem I have found is that underMin is evaluated like this:

    var underMin = minDate > new Date( Date.UTC(year, month-1, 1, 0, 0, 0 ) );

But, this will result in comparing the min date with the first date of previous month, which means that when you are on the next month compared to the minDate the left arrow won't show. Example: Assuming the minimum date is set to: 2018-01-30 and today is 2018-01-31, when you open the datepicker and click right (to see February) the underMin will compare 2018-01-30 with 2017-12-01, which results in TRUE and therefore the right arrow will be hidden. I think the correct way of evaluating the underMin variable should be like this:

         var underMin = minDate > new Date( Date.UTC(year, month, 1, 0, 0, 0 ) ); 

Hope it makes sense.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thank you! I completely missed that condition - my apologies. Yes, adding an if condition is the correct thing to do here and I've committed that into Editor now. It will be in 1.7.3 which I'll release next week as that's a fairly visible and UX detrimental bug.

    Allan

  • borconiborconi Posts: 56Questions: 19Answers: 1

    Glad to hear I was helpful.

  • cabcab Posts: 1Questions: 0Answers: 0

    Hi Allen

    Do you have any update for when 1.7.3 being released, although I notice the jquery-ui example works okay now?

    Thanks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I had been hoping it would be later today - but realistically I think it will probably slip into the start of next week now as there are a few more little things I want to look into first.

    Allan

  • nathan-glovernathan-glover Posts: 3Questions: 0Answers: 0
    edited July 2018

    Hi Allan,

    I'm still seeing the underMin bug borconi mentioned above in 1.7.4.

    In 1.7.4 underMin is defined as follows:

    if ( minDate ) {
        var underMin = minDate > new Date( Date.UTC(year, month-1, 1, 0, 0, 0 ) );
    
        this.dom.title.find('div.'+classPrefix+'-iconLeft')
            .css( 'display', underMin ? 'none' : 'block' );
    }
    

    His fix below worked for me. Is this something you'll look into fixing in a future version?

    var underMin = minDate > new Date( Date.UTC(year, month, 1, 0, 0, 0 ) );
    

    Thanks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    i've just had a look on this page and the original bug of the ">" button not showing in the calander does appear to work okay for me.

    Could you give me a link to a page showing the issue so I can debug it?

    Thanks,
    Allan

  • nathan-glovernathan-glover Posts: 3Questions: 0Answers: 0

    Allan, here is a link to a simple html page showing the problem.

    I'm showing the datepicker outside of the editor table in a regular input tag. I've seen the same issue when the datepicker is used within a table as well.

    Thanks for your help.

    https://nathan-glover.gitlab.io/datepicker-min-max-bug/

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Apologies for the delay in getting back to you here. Its top of my list for tomorrow!

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I'm with you know and completely concur on your fix. I've committed that in and it will be in the next release.

    Thanks for the test page, that was awesome!

    Allan

  • nathan-glovernathan-glover Posts: 3Questions: 0Answers: 0

    Thanks Allan!

This discussion has been closed.