Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

remerge(), reset(), resetData()

Avatar

Level 2

Can you reset the elements of a subform? Just a subform! Just like when it was first loaded? If so, how?

Subform contents are Textfields, DropDowns, DateFields, RadioButtons, etc?

Thanks in advance.

7 Replies

Avatar

Former Community Member

The resetData method allows you to pass a string representing a list of fields separated by commas (in the form of a SomExpression). You can try a subform and see if the child nodes get reset as I am not sure if it will only accept a field.

Paul

Avatar

Former Community Member

Similar to Paul's suggestion, I built a script to build a string containing all the names of the objects in a subform node of className 'field'. The string of field names is then passed to xfa.host.resetData().

Since the fields have to be comma-delimited, I concatenate the subform name, the field name, and a comma into a string called 'fieldStr'. The value of 'fieldStr' is then concatenated to a variable called 'fieldNames'. When I am done iterating over the subform node I then strip the last comma from the 'fieldName' string.

// form1.page1.subform1.resetBtn::click - (JavaScript, client)

var fieldNames = "";

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

     if (subform1.nodes.item(i).className == "field") {

          var fieldStr = "subform1." + subform1.nodes.item(i).name + ",";

          fieldNames = fieldNames + fieldStr;

     }

}

fieldNames = fieldNames.substring(0,fieldNames.length - 1);

xfa.host.resetData(fieldNames);

Steve

Avatar

Level 10

Hi Steve, I was just playing with your script as I have a similar problem in needing to reset fields in a subform, but when I try it it resets all data no matter what subform it's in.

I took your supplied sample and added another subform (not inside the existing subform) and it gets reset as well.

I've tried passing the fields as full strings for resetData("...") in a form I'm working on as well and seem to get the same results.

Any idea what's going on?

Avatar

Former Community Member

No. My script is definitely not much good.

1) I just realized radio button lists do not expose their 'name' attribute in 'field' so the script will never find radio buttons

2) I cannot get resetData() to recognize any programmiatic construction of a string of field names

On the other hand, when you build the resetData() as

xfa.host.resetData("form1.page1.subform1.TextField1,form1.page1.subform1.RadioButtonList");

it behaves a advertised.

Avatar

Former Community Member

The resetData is expecting a string that represents the object name. Are you passing in th entire object or the string of the name. You could use resetData(object.name)

Paul

Avatar

Level 10

Yeah, actually I've found there's a couple of different ways to pass the fields in...It doesn't need the full path, it just has to know where the field is.

xfa.host.resetData("form1.sMain.SubRegularSurplus.SubPositioned.Vote");

xfa.host.resetData("Vote");

It will reset the data in subforms:

xfa.host.resetData("form1.sMain.SubRegularSurplus.SubPositioned");

xfa.host.resetData(SubPositioned.somExpression);

Some of the weirdness I was getting was that it ws also resetting the visibility of the subform - Think I've got it figured out now. It behaves differently with subforms depending on the expression used.

If I use xfa.host.resetData("SubPositioned"); it resets everything on the form (needs the full path). If I use xfa.host.resetData("form1.sMain.SubRegularSurplus.SubPositioned"); it works ok. And if I use xfa.host.resetData(SubPositioned.somExpression); it works ok.

I found the "somExpression" version in a sample somewhere - not sure how it works...

Avatar

Level 3

Quite an old discussion this but thought I'd share my findings.

By re-using the lock fields script provided by pguerret, I've been able to reset data in particulare subforms as follows:

Call to the script object -

clearData.resetAllData(xfa.resolveNode("form1.subform1.subformIWantToReset"));

Then my script object looks like this:

function

resetAllData(myParentObject)

{

     var allChildElements;

     var intNumElements;

     var currentElement;

     var j;

     var temp;

     // get all the child nodes of the parent element

     allChildElements

= myParentObject.nodes;

    

     // total number of element in the object

     intNumElements

= allChildElements.length;

     // loop through all the child elements

     for(j=0; j<intNumElements; j++)

     {

          currentElement

= allChildElements.item(j);

          // if the element is another subform we'll recusively call the function again

          if(allChildElements.item(j).className == "subform")

          {resetAllData(currentElement);}

          // if the objects are fields

          else if(currentElement.className == "field")

          {

               temp = currentElement.name;

               if ((temp.substring(0,3) != "btn"))

               {xfa.host.resetData(currentElement.somExpression);}

          }

     }

}

My initial testing seems to suggest this has worked.