Sorting a repeating section - InfoPath Dev
in

InfoPath Dev

Sorting a repeating section

Last post 08-21-2006 12:22 PM by Agni Jonnalagadda. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-14-2006 04:36 PM

    Sorting a repeating section

    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
  • 08-21-2006 12:22 PM In reply to

    Re: Sorting a repeating section

    Hi, Probably there are some rules on the field(or its parent) that is bound to dropdown list that is causing the value getting set to default value.
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.