Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

Cannot get 'Remove' button to work correctly

Avatar

Level 5

I have a form that has 30 sections in it and in each section is a table that allows addition of a work code.  Along with the 'Add' button there is a 'Remove' button in case a work code is entered in error.  In the very first section this button works correctly, removing the last work code entered.  In all the other sections, subContract2 thru subContract30 the 'Remove' button does not work.  I thought I had it coded correctly but I'm apparently missing something.  Can someone review and identify the issue?  TIA.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

 

to be honest: You coding isn't great but overcomplicated. Why do you use the this.resolveNode() method? It's lazy and not needed when the elements in the hierarchy (subforms, fields etc.) are named well.You just have to image the location to the object that executes the script relative to the objects to be took into account by this. For example: tblWC1 and the buttons are very close together, just one level apart.

radzmar_0-1708456808635.png

 

Instead of using resolveNode starting at the button (this) to then reference to the its parent parent "subContractor" and then refer to the instanceManagager (_) of its child element (tblWC1)

this.resolveNode('subContractor._tblWC1').addInstance(1);
if (xfa.host.version <  {
xfa.form.recalculate(1);
}
this.resolveNode('Table1._subcontractor1Total').addInstance(1);
if (xfa.host.version <  {
xfa.form.recalculate(1);
}

 

… use the shortes possible reference indead.

_tblWC1.addInstance(true);

 

The some for the remove button. Use the shortest possible script.

_tblWC1.removeInstance(_tblWC1.count - 1);

 

You also using code to solve problems with Acrobat Reader 7 from 20 years ago. You don't need this since 2006 so get rid of it.

// Only for Acrobat 7 and before
if (xfa.host.version <  {
	xfa.form.recalculate(1);
}


Do this for all subseqent work code elements of your form to make it work.

 

 

Tipp: The script object "ColorFieldValitation" by default has an issue and often fails in the background with the error "oOriginalNode is null" "49:XFA:form1[0]:validationState" which also slows down your form.
To fix this, edit the script object starting in line 41 and replace …

		var oOriginalNode = xfa.resolveNode(sSOM);
		var oOriginalAssist = oOriginalNode.assist;
			
		if (!oOriginalAssist.isPropertySpecified("toolTip")) {
			var oToolTip = oInvalidNode.assist.toolTip;
			oInvalidNode.assist.nodes.remove(oToolTip);
		}

 

with …

		var oOriginalNode = xfa.resolveNode(sSOM);
		if (oOriginalNode !== null) {
			var oOriginalAssist = oOriginalNode.assist;
			
			if (!oOriginalAssist.isPropertySpecified("toolTip")) {
				var oToolTip = oInvalidNode.assist.toolTip;
				oInvalidNode.assist.nodes.remove(oToolTip);
			}
		}

 

 

 

 

 

 

 

View solution in original post

4 Replies

Avatar

Level 3

Reluctant,

 

The problem with the Subtract Work Code not working in the second instance of a Subcontractor is that  your code is not set to look at the last instance of our RepeatingRow2 table row. Try the first part of the code in the button this way:

 

var trRepCount = subContractor2.tblWC2.RepeatingRow2.instanceManager.count;
subContractor2.tblWC2._RepeatingRow2.removeInstance(trRepCount - 1);
if (xfa.host.version < {
xfa.form.recalculate(1);
}

Avatar

Correct answer by
Level 10

Hi,

 

to be honest: You coding isn't great but overcomplicated. Why do you use the this.resolveNode() method? It's lazy and not needed when the elements in the hierarchy (subforms, fields etc.) are named well.You just have to image the location to the object that executes the script relative to the objects to be took into account by this. For example: tblWC1 and the buttons are very close together, just one level apart.

radzmar_0-1708456808635.png

 

Instead of using resolveNode starting at the button (this) to then reference to the its parent parent "subContractor" and then refer to the instanceManagager (_) of its child element (tblWC1)

this.resolveNode('subContractor._tblWC1').addInstance(1);
if (xfa.host.version <  {
xfa.form.recalculate(1);
}
this.resolveNode('Table1._subcontractor1Total').addInstance(1);
if (xfa.host.version <  {
xfa.form.recalculate(1);
}

 

… use the shortes possible reference indead.

_tblWC1.addInstance(true);

 

The some for the remove button. Use the shortest possible script.

_tblWC1.removeInstance(_tblWC1.count - 1);

 

You also using code to solve problems with Acrobat Reader 7 from 20 years ago. You don't need this since 2006 so get rid of it.

// Only for Acrobat 7 and before
if (xfa.host.version <  {
	xfa.form.recalculate(1);
}


Do this for all subseqent work code elements of your form to make it work.

 

 

Tipp: The script object "ColorFieldValitation" by default has an issue and often fails in the background with the error "oOriginalNode is null" "49:XFA:form1[0]:validationState" which also slows down your form.
To fix this, edit the script object starting in line 41 and replace …

		var oOriginalNode = xfa.resolveNode(sSOM);
		var oOriginalAssist = oOriginalNode.assist;
			
		if (!oOriginalAssist.isPropertySpecified("toolTip")) {
			var oToolTip = oInvalidNode.assist.toolTip;
			oInvalidNode.assist.nodes.remove(oToolTip);
		}

 

with …

		var oOriginalNode = xfa.resolveNode(sSOM);
		if (oOriginalNode !== null) {
			var oOriginalAssist = oOriginalNode.assist;
			
			if (!oOriginalAssist.isPropertySpecified("toolTip")) {
				var oToolTip = oInvalidNode.assist.toolTip;
				oInvalidNode.assist.nodes.remove(oToolTip);
			}
		}

 

 

 

 

 

 

 

Avatar

Level 5

For the record, use of the "this.resolveNode" was suggested by this very site.

 

As for the suggestion of the using the shortest possible reference seems to have done the trick.  Thank you.

 

Avatar

Administrator

@ReluctantProgrammer Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni