When users are selecting a date i want the date to be between a range. e.g they can only select from 1st jan to 2nd march nothing else. Is there a way to be able to add this into the date field?
1 Answer
If you want to use the OOTB datefields you could probably just change the minjday
and maxjday
for the picker, but that only restricts the picker. They could still write a date that is not in the picker range, for that you'll have to add a change handler to the field. There is also a property called onvaluesetfrompicker
if i remember correctly that could be used.
Simple example for restricting the picker:
var getSPDayDiff = function(date) {
return Math.round(Math.abs( ( new Date(1601,0,1).getTime() - date.getTime())/( 24*60*60*1000 ) ) );
}
var minDay = getSPDayDiff( new Date(2015,0,1) );
var maxDay = getSPDayDiff( new Date(2015,2,2) );
var $trDateTimeControl = $("input[id='"+ g_strDateTimeControlIDs["SPDateField1"] + "']").closest("tr");
var dateTimeHtml = $trDateTimeControl.find(".ms-dtinput:eq(1)").html();
dateTimeHtml = dateTimeHtml.replace("minjday=109207", "minjday="+minDay);
dateTimeHtml = dateTimeHtml.replace("maxjday=2666269", "maxjday="+maxDay);
$trDateTimeControl.find(".ms-dtinput:eq(1)").html( dateTimeHtml );
minjday
and maxjday
are number of days sine 1/1/1601.
-
-
-
I also have requirement where i should disable the pastdates and also current date in date picker ,allowing user to pick the date that is not less than today. ![sharepoint date time control](i.sstatic.net/zjyby.png) when i inspect the element of date icon i seen following code: a **onclick**="**clickDatePicker**("ctl00_ctl39_g_1520de65_6f70_4c7f_b7b2_5578a563acda_ff241_ctl00_ctl00_ctl00_startDateTimeControl_startDateTimeControlDate", "\u002fsites\u002fPSEGPublishingsite\u002f_layouts\u002f15\u002fiframe.aspx?&cal=1&lcid=1033&langid=1033&ww=011– SwethaCommented Nov 18, 2017 at 19:41
-
@SwethaParitala Please if you have a new question you can post it here Commented Nov 19, 2017 at 10:17