Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Using a reset button for a dynamic table

Avatar

Level 1

I have a 6 page form that includes several dynamic tables. There is a reset button that clears only specific parts of the form because it is something that will be filled out weekly and a lot of the information will stay the same. My problem is that I want the reset button to clear specific rows of the table, but reset whatever is typed in the row for every instance in the table. The reset button only clears the row I want in the first column, not all the other columns/instances. Has anyone done this before or have any suggestions?

I don't want to include the whole script for the reset button because it has about 100 fields to clear but essentially this is what I have for the dynamic table and it works but only for the first column/instance, the rest stay the same:

 

xfa.host.resetData("form1.Page1.Subform1.Table1.Row5.Textbox1.somExpression");

1 Accepted Solution

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

3 Replies

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

Avatar

Level 1

Not sure what I'm doing wrong; nothing is resetting when the reset button is hit now.

Here's the script for my reset button:

if (xfa.host.messageBox("Do you want to clear all the weekly data from the form?", "Clear Weekly Data",2,2) == "4")

     {    

     ResetButton.resetData(form1);

     }

I put the function in form1.#variables[0].ResetButton - (JavaScript, client) and copied it exactly. I didn't put any of the scripts for the initialize events yets, just the function.

Any idea what I need to change?

Avatar

Level 10

I am not sure what the problem might be, if should have been as simple as that.  Would it be possible to publish your form so I can have a look.

Or maybe this example might help, https://acrobat.com/#d=kJotiuICMDo2ULbQ-EMW5g

Bruce