Repeating Section Issue

J

jpord

Using Infopath 2003 SP1

New to the Infopath world and I have a sample form where I have a
repeating table within a repeating section. Data is inserted into the
table when a checkbox is selected. When it is just the one section
there are "no issues". However, when after inserting subsequent
sections, and the checkbox is selected in those subsequent sections all
the additions go to the table in the first section. I suspect it is
related to using nodes but I am having difficulty finding the answer so
any help is appreciated. If any more information is need let me know.

Below is from the data source:

myFields
Group 3
Group 4 <=== Repeating Section
DemoCheck1 <=== Checkbox
DemoCheck2 <=== Checkbox
DemoCheck3 <=== Checkbox
Group 2 <== Repeating Table
field1
field2
field3

Below is the code in the form:

// The following line is created by Microsoft Office InfoPath to define
the prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-09-20T20:22:54"');
//</namespacesDefinition>

// The following function handler is created by Microsoft Office
InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
// This function is associated with the following field or group
(XPath): /my:myFields/my:DemoCheck1
// Note: Information in this comment is not updated after the function
handler is created.
//=======
function msoxd_my_DemoCheck1::OnAfterChange(eventObj)
{
// Write code here to restore the global state.
if (eventObj.IsUndoRedo || eventObj.Operation != "Insert")
{
// An undo or redo operation has occurred and the DOM is
read-only.
return;
}

//debugger;

var oNodeList =
XDocument.DOM.selectNodes("my:myFields/my:group3/my:group4" );
XDocument.UI.Alert(nodes.length);

if
(XDocument.DOM.selectSingleNode('/my:myFields/my:group3/my:group4/my:DemoCheck1').text
== "true")
{
var parent =
XDocument.DOM.selectSingleNode("/my:myFields/my:group3/my:group4")
var numRows =
XDocument.DOM.selectNodes("/my:myFields/my:group3/my:group4/my:group2").length;

//get first row
var rowOne = parent.selectSingleNode("./my:group2");
var rowOneFieldOne = rowOne.selectSingleNode("my:field1").text;

// Create xsi:nil attribute with the proper namespace.
var xmlNil = parent.ownerDocument.createNode(2, "xsi:nil",
"http://www.w3.org/2001/XMLSchema-instance");
xmlNil.text = "true";

if (numRows > 1 || rowOneFieldOne != "") {
//clone the first row
var rowClone = rowOne.cloneNode(true);
//reset values
var newdescription = rowClone.selectSingleNode("my:field1");
newdescription.text = rowOne.selectSingleNode("my:field1").text;
rowClone.selectSingleNode("my:field2").text =
rowOne.selectSingleNode("my:field2").text;
rowClone.selectSingleNode("my:field3").text =
rowOne.selectSingleNode("my:field3").text;

var olddescription = rowOne.selectSingleNode("my:field1");
olddescription.text = "Test";
rowOne.selectSingleNode("my:field2").text = "Info";
rowOne.selectSingleNode("my:field3").text = "Info";
// append row to XML document
parent.insertBefore(rowClone, rowOne);
}else
{
var olddescription = rowOne.selectSingleNode("my:field1");
olddescription.text = "Test 2";
rowOne.selectSingleNode("my:field2").text = "Sample Info";
rowOne.selectSingleNode("my:field3").text = "Sample Info";
}
}
}
 

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