Editor datepicker disable dates and ranges
Editor datepicker disable dates and ranges
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
This discussion has been closed.
Answers
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.
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
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?
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