Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Change DatePicker Min/Max Year View modes: 
User avatar
Member
Member
nanite2000 - 4/21/2013 7:46:24 PM
   
Change DatePicker Min/Max Year
I'm using Kentico v7.0.26.

Let's talk about that DatePicker control.

The standard user settings table has a field called 'UserDateOfBirth'. Usually you would expect people to enter a date in the past. I don't many 18 year-olds who were born tomorrow.

The standard DatePicker control always defaults to today. Even when you set it's maximum date to be 20 years in the past.

Worse still is that the minimum year is always set to 2003. Even when you set it to be 1900 in the form control settings.

How can we expect our public users to use this control? Is there a way to set the Min/Max years using a macro function so it doesn't affect the DatePicker when it is used elsewhere on the site?

Thanks.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 4/22/2013 2:13:29 AM
   
RE:Change DatePicker Min/Max Year
Hello,

Yes, you can easily extend this range, please read the following KB article: How to change a date picker (years) range?

Best regards,
Martin Danko

User avatar
Member
Member
@davey_lad - 4/23/2013 5:25:09 AM
   
RE:Change DatePicker Min/Max Year
With regards to the KB article workaround. Would custom changes to the javascript be potentially overwritten with Hotfixes or Update releases ?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/23/2013 7:04:37 AM
   
RE:Change DatePicker Min/Max Year
Hello,

If you not choose to overwrite all files at the beginning of the hotfix process, the modified files should be kept and the new ones from hotfix package would be copied with ".new" extension, so you could merge your customizations with the hotfix changes.
The upgrade to higher version should probably follow the same way, however the changes may be larger and more "enforced"... we will have to wait for the actual upgrade utility and instructions, but I wouldn't be worried about that.

To further comment your questions in your first post: I would probably recommend to clone the default Calendar form control (in Site manager -> Development-> Form controls)
with code in
~\CMSFormControls\Basic\CalendarControl.ascx.cs
and rename it to e.g. "BirthdayCalendar" - you will get another file name after cloning, but next to this file.

Then, in the Page_Load method, you will allow the limit and set the maximum limit and current selected date. It may look like this:

        timePicker.UseCalendarLimit = true;
timePicker.MaxDate = DateTime.Now.AddYears(-18);
timePicker.SelectedDateTime = DateTime.Now.AddYears(-18);

With this setup you can achieve a year dropdown that will allow to input birthdate only if you're over (or just turned) 18... for example.
Other conditions can be "simulated" with this approach as well.

Hope this will help.

Regards,
Zdenek

User avatar
Member
Member
@davey_lad - 4/23/2013 7:37:38 AM
   
RE:Change DatePicker Min/Max Year
Hi Zdenek,
Thanks for the info regarding the hotfix/upgrades. The second part of your post is for someone else however.

I do need some help with this one though if you're able :
http://devnet.kentico.com/Forums/f65/t36717/Date-Time-Picker-Validation.aspx

User avatar
Member
Member
nanite2000 - 4/23/2013 5:39:59 PM
   
RE:Change DatePicker Min/Max Year
kentico_zdenekc wrote: To further comment your questions in your first post: I would probably recommend to clone the default Calendar form control (in Site manager -> Development-> Form controls)
with code in
~\CMSFormControls\Basic\CalendarControl.ascx.cs
and rename it to e.g. "BirthdayCalendar" - you will get another file name after cloning, but next to this file.

Then, in the Page_Load method, you will allow the limit and set the maximum limit and current selected date. It may look like this:

        timePicker.UseCalendarLimit = true;
timePicker.MaxDate = DateTime.Now.AddYears(-18);
timePicker.SelectedDateTime = DateTime.Now.AddYears(-18);

With this setup you can achieve a year dropdown that will allow to input birthdate only if you're over (or just turned) 18... for example.
Other conditions can be "simulated" with this approach as well.

Hope this will help.

Regards,
Zdenek

Hi Zdenek,

While your suggestion will prevent people from selecting a year less than 18 years from the DatePicker, it will not stop them from typing it into the text box manually.

We use 'Site Manager -> Development -> System Tables -> User -> Alternative Forms' to collect user data. How can I add validation to the UserDateOfBirth field to ensure they enter a date more than 18 years old? In C# it would simply be one line of code:

EnterdDate < DateTime.Now.AddYears(-18)

Thanks.

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 4/24/2013 12:18:34 AM
   
RE:Change DatePicker Min/Max Year
Hi,

If you create a field with attribute type "Date and Time" and form control "Calendar" you can see that you may use the Validation option to set from/to. This however is only a partial solution and it might to be very precise...

The other thing you could do is to customize the webpart which is used for the form. You may inspire in the following example http://devnet.kentico.com/docs/devguide/index.html?modifying_the_code_of_standard_web_parts.htm

Kind regards,
Richard Sustek

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/24/2013 11:09:42 PM
   
RE:Change DatePicker Min/Max Year
Hi,

While it allows you to enter any date by typing, it shouldn't allow you to save the form with such date.
I've tested it with MyProfile web part in the sample Corporate site and the MaxDate/MinDate settings from the customized calendar were taken into account during validation.

Only the default User management UI pages (Administration - Users) use directly the DateTimePicker control, so the validation does not apply... you would need to add it in the specific page code.

Regards,
Zdenek