Skip to main content
Known Participant
February 22, 2023
Question

Javascript: Validation Error

  • February 22, 2023
  • 2 replies
  • 5581 views

Hey thanks for reading. 

 

I wrote a validation script for a dropdown field. If user selects x or y, an app alert asks for confirmation. If user selects no, I want the field to revert to y. But I'm receiving an: InvalidSetError: Set not possible, invalid or unknown specifically regarding the line that reverts the field value to y. I've tried referencing the export value of that dropdown option. still no luck. 

What am I doing wrong?

 

if (event.value !== "X" && event.value !== "Y") {
    var response = app.alert({
        cMsg: "Please confirm:...",
        nIcon: 3,
        nType: 2,
        cTitle: "selection",
        arrButton: ["Yes", "No"]
    });
    if (response === 4) {
      Additional.display = display.visible;

    }
else if (response === 3) {
app.alert("Please enter your Y")
field.value = "Y";
   Additional.display = display.hidden;
}}
This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
February 22, 2023

What are "Additional" and "field" in your script. These variables are undefined in the code, and will throw errors. 

 

The invalid set error means that the set value is not one of the items in the dropdown.   

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
dankpoochAuthor
Known Participant
February 22, 2023

 Additional and field in the code above represent variables declared elsewhere( var titleAdditional = this.getField("titleAdditional");) For brevity, I have here replaced mulitple such 'field display' codes. But I have verified the error lies not within.

As I mentioned to Bernd, I added onsole.println("event.value: " + event.value) to the else if block, which is correctly returning "Y" when the user selects No in the app.alert. In other words, the value of the field is returning as "Y" while the field still displays the users original response. 

Additionally, the Y response is surely a listed option in the dropdown menu. I've also tried turning off the field property checkbox "Commit selected value immediately". But this only delays the app.alert until the field is 'blurred' and has no effect on the value displayed within by the script. 

 

I'll reiterate in case it's important:

the script is in the dropdown's custom validation.

Also, is the set error being triggered because line 1 includes the condition "...event.value !== "Y"", while the else if block is trying to make the field = "Y"? I'm grasping at straws...

 

dankpoochAuthor
Known Participant
February 22, 2023

is it possible that "event" is not referring to the original field event, that it is instead referring to the users response to the app alert? 

i edited the else if block to include 

console.println("event.value: " + event.value + " fieldName.value: " + fieldName.value);

the console prints "event.value: Y fieldName.value: usersOriginalSelection"

Bernd Alheit
Community Expert
Community Expert
February 22, 2023

Use event.value = "Y";

 

dankpoochAuthor
Known Participant
February 22, 2023

event.value = "Y" was my first thought too. Then, I don't receive a set error, but the field value remains what the user originally selected. It does not change to Y when the user selects No.

dankpoochAuthor
Known Participant
February 22, 2023

I added console.println("event.value: " + event.value); to the else if block. When the user selects No, the console prints: event.value = Y. However, the field does not display Y. It displays the users original selection. 

Please. What? Why?