This tip comes directly from none other than Tanguy “The XRM Toolbox” Touzard himself.
It’s super easy to build an entity form and a page to allow editing of the Dynamics 365 records in a portal. But what if we want to restrict a date picker control to a certain range, which could be dynamic, e.g. based on today’s date.
Good news is that the portals use bootstrap framework so we should be able to use properties of the bootstrap date picker to set the range. The challenge is to get the actual control but for the master such as Tanguy, that’s not difficult.
The code that you’d want to add to Custom Javascript field of the entity form would look like the following:
$(document).ready(function() {
$("#foo_dateofbirth") // input control
.next() // the date picker container
.data("DateTimePicker") // the date picker object
.setMaxDate(moment()); // force the past
});
Here we’re forcing the date of birth to be in the past. You can use setMinDate(date) to restrict minimum date allowed as well.
Where I can register this script on form?
As per post:
Just copypaste the script into that field.
HTH
George
To restrict from selecting the past dates, mentioned script not working in CRM portal. It says setMinDate() is not a function
I’m not sure why it’s not working for you. Portals are using bootstrap datetime picker which has setMinDate() function defined. Are you saying that setMaxDate() is working?
Interesting. I just found some references that indicate that one should use minDate() instead of setMinDate(). Perhaps, these are the differences in bootstrap versions. Give it a try.
Thanks Man,
it helped me!!
miDate() and maxDate() worked for me.
Using the following code, forces the month and the day header columns into Chinese text the first time the date picker is selected…
$(document).ready(function() {
$(“#adv_requestedterminationdate”) // input control
.next() // the date picker container
.data(“DateTimePicker”) // the date picker object
.minDate(moment().add(7,’days’))
});
Any thoughts
maxDate(moment()) is working, but thanks for this good article
Is there a way to disable weekends also.
I have tried
$(‘#datefieldId’).datetimepicker(‘setDaysOfWeekDisabled’, [0,6]); but that is not working.
Not all properties and options seem to be available. e.g. Title, minViewMode etc.
Is there a way to disable textual input for date? As user will still be able to manually enter the past date even when they can’t select it in Date picker?
You can probably get to the text
<input>
control using jQuery and disable it there.Please do you have a solution??
Hi Diane,
have you checked Tip #1445: Date picker in Power Pages revisited?
Thanks
George