Skip to main content
Inspiring
November 11, 2021
Answered

Adding options and export values to dropdown box.

  • November 11, 2021
  • 1 reply
  • 723 views

I have a sheet where the number of fields is high but also variable project by project. I want to populate a dropdown with the fields to reduce the setup time for each new project.

 

Problem is I can't quite work out how set the export values as well. What I have so far:

 

 

function populateDD() {
    var fieldList = [];
    var exportMasks = [];
    for (var i = 0; i < numFields; i++) {                                // loop for each field in form
        if (-various statements to filter fields to the type I need for this list-){             
            exportMasks.push(this.getNthFieldName(i));
            var maskString = this.getNthFieldName(i).replace(/_/g," ");
            fieldList.push(exportString); 
        }
    }
    fieldList.sort();
    exportMasks.sort();
    this.getField(dropdownBoxInQuestion).setItems(fieldList, exportMasks);
}

 

I was hoping that would satisfy .setItems(option, export value) but it adds both arrays as options.

This topic has been closed for replies.
Correct answer Jimmy5E2F

I read over that but it's part of what lead me to where I am. I also tried merging the two arrays I showed above... 

 

I wen't back to the way I was combining the arrays, as everything else looked correct and indeed, I was just pushing one array into another. Worked fine once I combined them correctly.

 

    for (var i = 0; i < fieldList.length; i++){
        var tempArray = [];
        tempArray.push(fieldList[i]);
        tempArray.push(exportMasks[i]);
        dropdownList.push(tempArray);
    }
    this.getField("testDropDown").setItems(dropdownList);

1 reply

Bernd Alheit
Community Expert
Community Expert
November 11, 2021

Look at the Acrobat Javascript Reference for a sample.

Jimmy5E2FAuthorCorrect answer
Inspiring
November 11, 2021

I read over that but it's part of what lead me to where I am. I also tried merging the two arrays I showed above... 

 

I wen't back to the way I was combining the arrays, as everything else looked correct and indeed, I was just pushing one array into another. Worked fine once I combined them correctly.

 

    for (var i = 0; i < fieldList.length; i++){
        var tempArray = [];
        tempArray.push(fieldList[i]);
        tempArray.push(exportMasks[i]);
        dropdownList.push(tempArray);
    }
    this.getField("testDropDown").setItems(dropdownList);
Known Participant
October 23, 2022

Then what will be the total code? Thanks