Date Picker --Need to pick Friday of the week

G

Gurmit

Hi, i'm new to infopath, i'm designing a simple timesheet form with a date
picker control. I want users to always pick Friday of the week(any week). If
user pick a date other than friday, it displays an error or something like
that. or if this is not possible can I put default value of date control as
Friday of the week.
Thanks,
 
S

S.Y.M. Wong-A-Ton

Both are possible, but you'll have to write code to get this done.

- Add a date picker to your form and change its name to "date".
- Copy the isDay() function from
http://enterprise-solutions.swits.net/infopath/switch-day-sections-jscript-xdextensions.htm to your form's code.
- Add an OnValidate event for the "date" field to your form's code and then
add the following code to this event handler:

if (!isDay(5))
{
var objDate = XDocument.DOM.selectSingleNode("//my:date");
eventObj.ReportError(objDate, "Date must be a Friday", false);
return;
}

This code will prevent the form to be submitted unless the day is a Friday
and will show a red field validation error border around the "date" field and
a tooltip with the text "Date must be a Friday" whenever the user hovers with
the mouse pointer over the "date" field.

For more information on OnValidate and ReportError see
http://msdn.microsoft.com/library/en-us/ipsdk/html/xdevtOnValidate_HV01021372.asp?frame=true
 
G

Gurmit

Thanks, this is a great help.
--
Gurmit Singh


S.Y.M. Wong-A-Ton said:
Both are possible, but you'll have to write code to get this done.

- Add a date picker to your form and change its name to "date".
- Copy the isDay() function from
http://enterprise-solutions.swits.net/infopath/switch-day-sections-jscript-xdextensions.htm to your form's code.
- Add an OnValidate event for the "date" field to your form's code and then
add the following code to this event handler:

if (!isDay(5))
{
var objDate = XDocument.DOM.selectSingleNode("//my:date");
eventObj.ReportError(objDate, "Date must be a Friday", false);
return;
}

This code will prevent the form to be submitted unless the day is a Friday
and will show a red field validation error border around the "date" field and
a tooltip with the text "Date must be a Friday" whenever the user hovers with
the mouse pointer over the "date" field.

For more information on OnValidate and ReportError see
http://msdn.microsoft.com/library/en-us/ipsdk/html/xdevtOnValidate_HV01021372.asp?frame=true
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top