Copy and Pasting Working Dropdown that hides/shows other fields does not work, even when everything is renamed.

Avatar

Avatar

kevm75130910

Avatar

kevm75130910

kevm75130910

19-10-2018

Like the title hints, i copy and past a working Drop Down and even when i rename everything, it does not work.
I have done both copy and pasting of the objects and creating them from scratch, with the same non-results.

I did not write the code, nor do i fully understand it, especially why its not working.

This is the one that works:

DD is the Drop down

Ordering is the text area to the right of the drop down.  It should be shown or hidden depending if the Drop Down value is Yes (1) or No (0), respectively.

Row is shown on a different page and uses an add/remove function.

1600569_pastedImage_0.png

WORKING CODE:

form1.#subform[1].DDScrubs4me::change - (JavaScript, client)

if ($.boundItem(xfa.event.newText) == "Yes") {

  this.resolveNode('Table1._Scrubs4MeRow').addInstance(1);

  if (xfa.host.version < 😎 {

  xfa.form.recalculate(1);

  }

  this.resolveNode("Scrubs4meOrdering").presence = "visible";

}

if ($.boundItem(xfa.event.newText) == "No") {

  this.resolveNode("Scrubs4meOrdering").presence = "invisible";

  this.resolveNode('Table1._Scrubs4MeRow').removeInstance(0);

  if (xfa.host.version < 😎 {

  xfa.form.recalculate(1);

  }

}

//+ GENERATED - DO NOT EDIT (ID:B66FA27E-80E0-4049-A24A-2B81F5F29055 CRC:973936563)

if ($.boundItem(xfa.event.newText) == "Yes" && this.resolveNode("PromptOff").rawValue == "0" && (this.resolveNode("Scrubs4meOrdering").rawValue == null || this.resolveNode("Scrubs4meOrdering").rawValue == "")) {

  xfa.host.messageBox("Please enter your facility's entity code", "Code needed.", 3);

}

//-

This is the one that was copied and does not work:

1600570_pastedImage_29.png

CODE FROM COPIED DROP DOWN WITH OBJECTS RENAMED:

form1.#subform[1].DDSNH::change - (JavaScript, client)

if ($.boundItem(xfa.event.newText) == "Yes") {

  this.resolveNode('Table1._SNHRow').addInstance(1);

  if (xfa.host.version < 😎 {

  xfa.form.recalculate(1);

  }

  this.resolveNode("SNHOrdering").presence = "visible";

}

if ($.boundItem(xfa.event.newText) == "No") {

  this.resolveNode("SNHOrdering").presence = "invisible";

  this.resolveNode('Table1._SNHRow').removeInstance(0);

  if (xfa.host.version < 😎 {

  xfa.form.recalculate(1);

  }

}

if ($.boundItem(xfa.event.newText) == "Yes" && this.resolveNode("PromptOff").rawValue == "0" && (this.resolveNode("SNHOrdering").rawValue == null || this.resolveNode("SNHOrdering").rawValue == "")) {

  xfa.host.messageBox("Please enter your facility's entity code", "Code needed.", 3);

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar

kevm75130910

Avatar

kevm75130910

kevm75130910

22-10-2018

Thank you for your expertise. I was unable to get your code to work, but when using the original code and viewing the errors in Acrobat DC, i get this:

GeneralError: Operation failed.

XFAObject.addInstance:2:XFA:form1[0]:#subform[1]:DDSNH[0]:change

The element [max] has violated its allowable number of occurrences.

It seems that i has one thing misspelled and i changed the BINDING of the ROW to the Repeating Data with the MAX checked with a value of 1.

That fixed it.

Thank you for your help.  You saved all the bacon!

Avatar

Avatar

radzmar

MVP

Total Posts

(val/1000)?string[".0"]}K

Likes

385

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

(val/1000)?string[".0"]}K

Likes

385

Correct Answer

485
radzmar
MVP

20-10-2018

The code is ok, but may not work because the resolveNode() method doesn't find the named objects. Without knowing the entire structure it's not possible to answer that for sure. Open your form in Acrobat, press [Ctrl]+[J] to open the JavaScript console: Then change the dropdown list value and look for any errors in den console window.

Note: When you use this.resolveNode() the method only looks for objects in the same branch of the XML-tree as the script executing object resides. When you use xfa.resolveNode() instead, the search starts always at the root node of the XML-tree.

Alternatively try this script:

var cSelection = this.rawValue,

    oRow = xfa.resolveNode("form1..Table1._SNHRow"),

    oField1 = xfa.resolveNode("form1..PromptOff"),

    oField2 = xfa.resolveNode("form1..SNHOrdering");

oRow.setInstances(cSelection === "Yes" ? 1 : 0);

oField2.presence = cSelection === "Yes" ? "visible" : "hidden";

if (cSelection === "Yes" && oField1.rawValue === "0" && oField2.isNull) {

xfa.host.messageBox("Please enter your facility's entity code", "Code needed.", 3, 0);

}