Editor datepicker disable dates and ranges

Editor datepicker disable dates and ranges

epoch1epoch1 Posts: 17Questions: 8Answers: 1

Hi,

Is it possible to disable individual dates or date ranges in the jQuery datepicker in Editor? Something like:

var disabledDate = ["22-05-2018","26-05-2018"...];

opts:  {
    minDate: new Date(),
    beforeShowDay: function(date) {
        var string = jQuery.datepicker.formatDate('dd-mm-yyyy', date);
        return [ disabledDates.indexOf(string) == -1 ]
    }
}

Cheers

MJ

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    https://editor.datatables.net/reference/field/datetime

    I found this on the above page:

    "opts.disableDays null
    This option can be used to disallow user selection of certain days or dates in the calendar picker. As an array the values are week day indexes for the days that should be disabled, where 0 is Sunday, 1 Monday, etc. This array form is useful for repeating patterns such as disabling Saturday and Sunday.

    As a function, it is called for every day to be displayed in the calendar and a Date object is passed in representing that day. Returning true will disable that day, while all other return values will allow it to be selected by the end user.

    Please note that the user will still be able to enter dates which have been disabled through this option using keyboard input, so server-side validation should also be performed."

    This is obviously not what you need but I find the last paragraph remarkable: You will need server side validation anyway to be sure. Hence I would use a validator on the server side and check those dates there.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Currently no - that is something that the datetime input does not allow for I'm afraid. You'd need to use an external library such as jQuery UI date picker for such functionality.

    Regards,
    Allan

  • epoch1epoch1 Posts: 17Questions: 8Answers: 1

    So if I need to restrict dates should I just make it a text field and trigger the date picker myself so that I can configure the options?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Effectively yes. A plug-in for Editor would need to be created and there are a few on the Editor plug-ins page already such as for the Bootstrap date picker.

    The built in datetime has the option to set max and min dates, but not individual dates.

    Allan

This discussion has been closed.