Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScript Not Equal: What is the proper syntax for calling a function that isn't equal to custom text?

Engaged ,
Dec 09, 2016 Dec 09, 2016

I'm creating a form that lists employee names and using a document level function that calls an variable array in a custom keystroke script in a combobox.

The end goal is to auto populate the employee's supervisor if the event will commit. Both are comboboxes and both are set to allow the user to enter custom text. I wanted to provision for new hires whose name may not be in the combobox yet.

The code works and I've been using it for years, however I want to create a condition that states if the event value does not equal the function, it resets the supervisor combobox. I wanted to do this in the event the employee looks for their name but can't find it and it ends up populating with someone else's name.

How would I go about this? If I take out lines 7-9 of the custom keystroke script, the script works except for the condition in which custom text is entered.

Document Level Function:

//I left out the variables but below is a one line example of it.

var getSupervisor = {"Employee Name":{ supervisor: "Supervisor Name"}};

function supV(svName) {

     this.getField("supervisor").value = getSupervisor[svName].supervisor;

}

Custom Keystroke Script:

//I tried this code with both the not equal (!=) and not equal value or type (!==) operators as well as leaving "event.value" out of calling the function and neither worked.

if( event.willCommit ) { 

    if(event.value == " ") {

  this.resetForm(this.getField("supervisor"));

    }

    else if(event.value !== supV(event.value)) {

  this.resetForm(this.getField("supervisor"));

    }

else {

     supV(event.value);

}

}

TOPICS
Acrobat SDK and JavaScript , Windows
5.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

The resetForm method takes the name of a field, or fields, as its parameter, not a Field object.

Try using this code instead:

this.resetForm(["supervisor"]);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 09, 2016 Dec 09, 2016

I tried your suggestion but it didn't seem to work. I've created a workaround, however by changing the keystroke script to simply call the function on will commit and anything else will simply reset the supervisor field.

I had provisioned for the blank combobox selections in the document level script anyway, so resetting the field based on the blank option was really redundant.

Thanks for the suggestion! I didn't realize I only had to call out the field name.

Updated keystroke script:

if(event.willCommit) { 
supV(event.value);
    }
else {
this.resetForm(["supervisor"]);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 09, 2016 Dec 09, 2016
LATEST

New issue: The above solution I came up with is now causing another issue that I've never come across.

If I try to type custom text in the employee field, the script keeps running after every character. This is not allowing me to type more than one character every few seconds and won't be acceptable. What's odd is it wasn't doing that until after I saved, closed out of Acrobat, and reopened.

Note:

  • Commit selected value immediately was checked on (still doesn't work if checked off)

Is there a way to stop a script from continually running. I'm not getting why it's running after every character?

I'm welcome to any suggestions, even running another type of event instead of custom keystroke, maybe a validation event, maybe put a return in the script, etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines