In our Servoy application, a lot of Calendars are used to allow datetime entries. New requirements specify that almost every one of them should not allow entering a datetime that lies in the future.
Obviously, I want to customize the Calendar component for this rather than modify every instance - but I haven’t got a clue how to go about it. I’m fairly new to Servoy.
Ideally, I’d add an extra boolean property, ‘allowFutureDates’ that defaults to false, and if it is false, future dates don’t show up in the Calendar at all. But that is probably too much to ask for.
Can somebody get me in the right direction for handling this - or even better, give an example – or still even better, both?
if you are using the Calendar component from the BootstrapComponent package insted of the Default Package is possible to set a max/min date at runtime:
This has to be done for every single calendar element;
You can iterate over all your elements at the onShow of the form and set a min/max date for all your calendar elements
for (var i = 0; i < elements.allnames.length; i++) {
/** @type {RuntimeWebComponent<bootstrapcomponents-calendar>} */
var el = elements[elements.allnames[i]];
if (el.getElementType() == "bootstrapcomponents-calendar") {
el.setMinMaxDate(minDate,maxDate);
}
}
Up to you to handle exceptions where you want to allow future dates.
Note: I am using the new RuntimeWebComponent type in JSDoc from the latest Servoy release 2019.09.RC1
When you have another problem, you could also check the datetime-picker from mindfire.
It comes with source code, which means you can change anything you want.
We made good experience with it, and customisation abilities are really good.