Hi,
I have a form that has a repeating section. Inside, there are multiple text fields and one dropdown list. There is a button that allows the user to sort his entries by date. Everything works fine except the dropdown list keeps getting reset to the default value instead of the selected value which means after the user has sorted the list, they have to go back through and change the dropdown lists again.
Below is the code that does the sort.
//=======
// 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.
//=======
function buttonSort::OnClick(eventObj)
{
// Write your code here
sort("/my:ExpenseClaim","my:ExpenseItems",compareDates);
}
function compareDates(xmlDateLeft, xmlDateRight)
{
var xmlLeft = xmlDateLeft.selectSingleNode("my:Date");
var xmlRight = xmlDateRight.selectSingleNode("my:Date");
var valueLeft = xmlLeft.text.split("-");
var valueRight = xmlRight.text.split("-");
var dateLeft = new Date(valueLeft[1] + "-" + valueLeft[2] + "-" + valueLeft[0]);
var dateRight = new Date(valueRight[1] + "-" + valueRight[2] + "-" + valueRight[0]);
if (dateLeft < dateRight)
return -1;
else if (dateLeft > dateRight)
return 1;
else
return 0;
}
function sort(xpathParent, xpathChildren, fnCompare)
{
// Retrieve the parent node; all the children will be sorted.
var xmlOrigParent = getNode(xpathParent)
var xmlItems = xmlOrigParent.selectNodes(xpathChildren);
if (1 < count(xmlItems))
{
// Store the (pointers to) items in an array for faster access.
rgItems = new Array();
while (xmlItem = xmlItems.nextNode())
{
rgItems.push(xmlItem);
}
// Sort the array (the XML does not change).
rgItems.sort(fnCompare);
var xmlClones = xmlOrigParent.selectNodes(xpathChildren);
for (var i=0; i<rgItems.length; i++)
{
xmlOrigParent.replaceChild(rgItems.cloneNode(true),xmlClones);
}
}
}
I am at a loss as to why this is happening. I would appreciate any suggestions.
Thanks,
Rhonda