Populate drop box based on value of date picker

D

david

Hi,

I have a form with a date picker, and I would like to populate a drop
box with the next 5 dates based on the selection of the date picker.

For example:

Date: 01-Nov-2006

I would like the drop list to contain:

01-Nov-2006
02-Nov-2006
03-Nov-2006
04-Nov-2006
05-Nov-2006

Any pointers/samples? I've never used C, but am pretty good with
javascript so should be able to follow any technical posts.

Many thanks,

David.
 
B

Ben Walters

Hey David,
You'll probably need to do a bit of coding, but here is my idea.
map your drop down list to a repeating field in your xml structure
<datelist/> for example, Add an on change evnent to your Date picker control.
When the user selects a date, run a loop statement 5 times each time adding a
new record to your datelist repeating field.

I haven't tried coding this yet but if you need some samples let me know and
I'll do some up

Hope this helps

Cheers
Ben
 
D

david

Hi Ben,

If you have time for a sample that would be great. I haven't had to do
any coding within InfoPath so far so not sure how form objects are
named and what events are available for embedding code. InfoPath seems
to be surprisingly powerful for what it is.

Thanks,

David.
 
B

Ben Walters

Hey David,
More than happy to do up some code for you just wanted to check and see if
your using InfoPath 2007 or 2003?
Cheers
Ben
 
D

david

Hi Ben,

Thanks for this. I am using 2003 unfortunately, I understand that there
is a function built into 2007 to do this? Shame. We won't be getting
this here until May!

Regards,

David Smyth.
 
B

Ben Walters

Hey David sorry this took so long to get back to you with but I had to get a
machine up and running with InfoPath 2003 again.


I've got some C# code here that should help you.

1: Create a new InfoPath form.
2: Add 1 Date Picker control and 1 Drop down list to the form
3: In the data source tab add one new repeating field called "FutureDates"
4: open the properties for the drop down list and set the list to get it's
values from the future dates repeating field
5: open the properties for the date picker control and add an On After
changed event to the form
6: Insert the folling code in the OnAfterChangeEnvent

if (e.NewValue != null)
{
//Get the currently selected date
DateTime selectedDate =
DateTime.Parse(e.XDocument.DOM.selectSingleNode("my:myFields/my:field1").text);

//Get any existing dates
IXMLDOMNodeList existingDates =
thisXDocument.DOM.selectNodes("my:myFields/my:FutureDates");

//If there are existing dates then removed them
if (existingDates.length > 1)
{
foreach (IXMLDOMNode dateToRemove in existingDates)
{
if
(thisXDocument.DOM.selectNodes("my:myFields/my:FutureDates").length != 1)
{

thisXDocument.DOM.selectSingleNode("my:myFields").removeChild(dateToRemove);
}
}
}


//lun the loop 5 time
for (int i = 0; i < 5; i++)
{
// if this is the first time the loop has run then set
the existing nodes value
if (i == 0)
{

thisXDocument.DOM.selectSingleNode("my:myFields/my:FutureDates").text =
selectedDate.ToString();
}
else //increment the date by one day then add it to the
list
{
IXMLDOMNode DateToAdd =
thisXDocument.DOM.selectSingleNode("my:myFields/my:FutureDates").cloneNode(true); ;
DateToAdd.text = selectedDate.AddDays(i).ToString();

thisXDocument.DOM.selectSingleNode("my:myFields").appendChild(DateToAdd);
}
}
}


Hope this helps, if you need any more help let me know and I'll put some
directions up on my blog

Cheers
Ben
 

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