Changes to Default Field in Date Picker Not Saving

M

Mrs. Help Menu

I am by no means XML saavy, so I designed my custom form template using the
pre-set controls. Users complained that when entering future dates in a Start
and End date picker, they had to scroll through the date picker for both
fields. They requested the calendar for the endDate field be in the same
month as the startDate when they select it. My remedy was to set the default
value for endDate to equal startDate. However, despite the date being fully
edit-able and seeming to save normally, when the completed .xml forms are
re-opened, the endDate has reverted to the default value (startDate). This is
causing a problem when I want to merge the forms and export them to Excel, as
the values as entered are not captured. Is there something I'm doing wrong,
or should I be taking a different approach?
 
F

Franck Dauché

Hi,

You should be able to do this. How do you actually do it? To make sure
that the end date value is updated properly, you need to change the value of
the node linked to your end date on the fly each time the start date is
updated.
One easy way to do this is to use the OnAfterChange event of your start date
field to trigger a value for your end date.

If you look at a question from yesterday in this newsgroup with the title
"Date Picker Calculation", you will find in my last answer some code sample
to set the value of a second Date Picker based on the value of the first one
by code.

Hope it helps you.

Franck Dauché
 
M

Mrs. Help Menu

Hello, Franck. Thank you so much for your quick response! One clarification,
if I may: Does this code save the changes users may make to the End Date? In
other words, code allowing me to set the End Date automatically is great but
is secondary to concerns I have about changes being captured when users type
over the pre-set value to enter their own. Apologies if that's what you're
addressing with the suggested code fix below.
 
M

Mrs. Help Menu

Actually, after reading the blog and the fix you hand-wrote, I'm afraid my
above question is irrelevant. I quite simply don't know where to begin! What
is an IP project? #c? Visual Studio? Yikes! So sorry to be so utterly dense,
but I'm afraid perhaps I'm in over my head here.
 
F

Franck Dauché

Well, may I can try to help you. Try to follow the following procedure and
let me know if it helps:

create new InfoPath form
Drop 2 date picker controls on your page (you now have 2 fields in your
schema: field1 and field2).
Right-click on 1st Date Picker / Click on Properties / On the Data Tab,
select Data Validation
In the Event drop-down, select OnAfterChange / Click Edit
You are now in the scripting page
change the function named: function msoxd_my_field1::OnAfterChange(eventObj)
to look like this

function msoxd_my_field1::OnAfterChange(eventObj)
{
if (eventObj.IsUndoRedo)
{return;}

var dateNode = XDocument.DOM.selectSingleNode( "//my:field2" );
dateNode.removeAttribute("xsi:nil");
dateNode.text = getDateString();

}

below that function copy the following code:

function getDateString(oDate) {
// Use today as default value.
if (oDate == null)
oDate = new Date();
var m = oDate.getMonth() + 1;
var d = oDate.getDate();
if (m < 10)
m = "0" + m;
if (d < 10)
d = "0" + d;
// ISO 8601 date (YYYY-MM-DD).
return oDate.getFullYear() + "-" + m + "-" + d;
}

save and close the scripting editor.
run your form, pick 1 date in Date Picker 1, Date Picker 2 fills up with
today's date...

Franck Dauché
 
M

Mrs. Help Menu

Wonderful; thank you!!

Franck Dauché said:
Well, may I can try to help you. Try to follow the following procedure and
let me know if it helps:

create new InfoPath form
Drop 2 date picker controls on your page (you now have 2 fields in your
schema: field1 and field2).
Right-click on 1st Date Picker / Click on Properties / On the Data Tab,
select Data Validation
In the Event drop-down, select OnAfterChange / Click Edit
You are now in the scripting page
change the function named: function msoxd_my_field1::OnAfterChange(eventObj)
to look like this

function msoxd_my_field1::OnAfterChange(eventObj)
{
if (eventObj.IsUndoRedo)
{return;}

var dateNode = XDocument.DOM.selectSingleNode( "//my:field2" );
dateNode.removeAttribute("xsi:nil");
dateNode.text = getDateString();

}

below that function copy the following code:

function getDateString(oDate) {
// Use today as default value.
if (oDate == null)
oDate = new Date();
var m = oDate.getMonth() + 1;
var d = oDate.getDate();
if (m < 10)
m = "0" + m;
if (d < 10)
d = "0" + d;
// ISO 8601 date (YYYY-MM-DD).
return oDate.getFullYear() + "-" + m + "-" + d;
}

save and close the scripting editor.
run your form, pick 1 date in Date Picker 1, Date Picker 2 fills up with
today's date...

Franck Dauché
 

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