Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Javascript protecting and opening field problem

Avatar

Level 2

I have a Form with two fields that I do not want the user to complete. The first field txtCIC is at the top of the Form and only occurs once. The second field txtPICode is within a row instance that the user creates as required. I have another field identified for the person handling the Form to access the two protected fields through entering a code. After updating the two fields the code is removed to protect the fields again.

I inserted the script in the layout:ready event.

if (this.rawValue == "1234") {

PR20.Body.sfFrame.sfProperty.txtCIC.access = "open";

  PR20.Body.sfFrame.sfRows.txtPICode.access = "open";

}

else {

PR20.Body.sfFrame.sfProperty.txtCIC.access = "protected";

PR20.Body.sfFrame.sfRows.txtPICode.access = "protected";

}

The script prevents entry to the two fields until the value "1234" is entered and removed. My problem is if I create more than one row instance only row one is protected.

Can anybody please help me?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

this requires a loop to find all instances of the desired fields.

Put this script into the exit:Event.

var nRow = xfa.resolveNodes("PR20.Body.sfFrame.sfProperty[*]");

var nTestValue = "1234";

 

for (var i = 0; i < nRow.length; i += 1) {

          nRow.item(i).txtCIC.access = this.rawValue === nTestValue ? "open" : "protected";

          nRow.item(i).txtPICode.access = this.rawValue === nTestValue ? "open" : "protected";

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

this requires a loop to find all instances of the desired fields.

Put this script into the exit:Event.

var nRow = xfa.resolveNodes("PR20.Body.sfFrame.sfProperty[*]");

var nTestValue = "1234";

 

for (var i = 0; i < nRow.length; i += 1) {

          nRow.item(i).txtCIC.access = this.rawValue === nTestValue ? "open" : "protected";

          nRow.item(i).txtPICode.access = this.rawValue === nTestValue ? "open" : "protected";

}

Avatar

Level 2

Thank you for taking the trouble.