Avatar

Correct answer by
Level 10

Hi,

I’m not sure I understand your exact scenario but I use a function in a script object that I pass in a subform (possibly the top subform to reset the whole form) and the function resets all fields within it. 

function resetData(node)

{

    if (node.className === "field")

    {

        var enableResetData = node.desc.nodes.namedItem("enableResetData");

        if (enableResetData === null || enableResetData.value === true)

        {

            // reset all fields except those with enableResetData set to false

            node.rawValue = null;

        }              

    }

    else

    {

        for (var i = 0; i < node.nodes.length; i++)

        {

            var currentNode = node.nodes.item(i);

            if (currentNode.isContainer)

            {

                // ignore some form objects

                if (currentNode.className !== "draw" &&

                    currentNode.className !== "variables")

                {

                    resetData(currentNode);

                }

            }

        }

    }

}

If there are any fields that I don’t want reset I put the following code in the initialise event of those fields.  Depending on the number of fields involved you might what to reverse this logic.  (you could also add the desc.enableResetData element in the XML Source view)

var enableResetData = this.desc.nodes.namedItem("enableResetData");

if (enableResetData == null)

{

    enableResetData = xfa.form.createNode("boolean", "enableResetData");

    this.desc.nodes.append(enableResetData);

}

enableResetData.value = true;

This works by storing a value “enableResetData” in the desc element of the field, allowing a generic function to have specific behaviour for particular fields.

Hope this helps.

Bruce

View solution in original post