How do I disable certain dates on date picker?

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
thebrightlord
Posts: 12
Joined: Wed Nov 13, 2019

19 Nov 2019

Not seeing documentation on how to do that, just for disabling entire fields...

I tried this code:
function setToDateRange() {
fd.field('Effective_x0020_Date').control('kendoDateTimePicker')
.done(function(picker) {
picker.setOptions({
min: 2,
max: 30
});
});
Didn't work

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

20 Nov 2019

Hello thebrightlord,

You can disable specific dates in the month with the following code. Replace 'Date' with the internal name of your field. If you use Date Only fields, replace 'kendoDateTimePicker' with 'kendoDatePicker'.

Code: Select all

fd.field('Date').control('kendoDateTimePicker').done(function(picker) {
		picker.setOptions({
			    value: new Date(),
			    disableDates: function (date) {
			        var disabled = [2,30];
			        if (date && disabled.indexOf(date.getDate()) > -1 ) {
			            return true;
			        } else {
			            return false;
				        }
				    }
		});
});

thebrightlord
Posts: 12
Joined: Wed Nov 13, 2019

20 Nov 2019

Thank you Margarita.

Your code sparked an idea and I modified it to this:

Code: Select all

var today = new Date();
var minDate = today.setDate(today.getDate()+2);
var maxDate = today.setDate(today.getDate()+30);

fd.field('Effective_x0020_Date').control('kendoDatePicker').done(function(picker) {
		picker.setOptions({
		min: new Date(minDate),
		max: new Date(maxDate)
		})
});
I needed to only allow 2 days past today as minimum and 30 days past today as maximum.

Tanja1980
Posts: 2
Joined: Mon Jan 29, 2018

12 Mar 2020

I have similar issue, but I can't get the code to work...

I have Date Picker field, but in Related Items in Quick Edit Mode and need to allow entries for only the past 3 days.

I tried both upper codes (I even replaced fd.field with fd.relatedItems), but no succes. Does the code differ, if the field is in Related Items?

Regards,
Tanja

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

16 Mar 2020

Hello Tanja1980,

I'm sorry for the delay in reply!

This approach is not applicable to the Date column in related items. And It is not possible to interact with Related items in quick edit mode using JS.

But you can try out the SharePoint column validation. Please find more information in this article:
https://support.office.com/en-us/articl ... 7ebf6988b3

And in this post:
https://sharepoint.stackexchange.com/qu ... odays-date

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests