Date Template Part for InfoPath 2007

The date picker for InfoPath 2007 is just fine, except maybe when you want to select a birth date.
Then the user has to navigate back like so many clicks to get the year / month he was born into.

Thus when selecting a birth date, there is nothing better that the standard 3 drop down lists.

However InfoPath 2007 does not provide such a control to validate the entered date automatically.
So you would have to go through alot of trouble to create multiple rules / validations to get the desired effect.
For example, if the user selects 30th of February at any year, this should not be valid, also if the user selected 29th of February in a non leap year, this also should not be valid.

I have created this template part to re-use whenever i want in such cases, it has all the validations already done.

You can download the template part from here: DateTemplateGroup

In order to use the template part in any form template, kindly follow these steps:

  • Download the template part from here
  • Extract it to a location of your choice
  • Open your form template in Design Mode
  • In the Design Tasks Panel, click “Controls” then “Add or Remove Custom Controls”

    Add Custom Control

    Figure 1.1

  • Click the “Add” button on the “Add or Remove Custom Controls” Window

    Add or Remove Custom Controls

    Figure 1.2

  • Choose “Template Part” and click “Next” on the “Add Custom Control Wizard”

    Add Custom Control Wizard - Template Part

    Figure 1.3

  • Browse to DateTemplateGroup.xtp file you extracted and click “Finish” then “Close”

    Add Custom Control Wizard - Browse

    Figure 1.4

  • Now the Date Template Group has been successfully added to your Controls, you can now drag one into your form.

    DateTemplateGroup

    Figure 1.5

  • The control looks a bit awkward in design mode, but it will look perfect in preview mode.

    Data Template Group Control

    Figure 1.6

Here is how it looks in Preview Mode

Date Template Group Control - Preview

Figure 1.7

As you can see the control will validate the date entered, and will only accept possible values. It is also browser-enabled so you can use it in InfoPath Forms Services just fine. You can also customize it in anyway you like in terms of the look and feel and the logic.

The logic of this control is pretty straight forward.
A “Year” and “Month” drop down lists to contain “Year” and “Month” Values, and 4 “Day” drop down lists, each for every possible list of days (1 ~ 28, 29, 30, 31).
Conditional Formatting has been performed on the 4 “Day” drop down lists, so that only one will show for any combination of “Year”/”Month”.
And Validations on the “Day” data source field validates the date correctness.

See you soon,

Hazem Elshabini

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s