javascriptmobileadobeacrobatacrobat-sdk

Object.keys() on mobile environment (Adobe Acrobat Reader)


i'm trying to iterate over some Object keys and then fill some DropDowns with the values. On the PC it's working perfectly fine with every solution i've tried - unfortunately on mobile it's not.

So here's what i've tried:

 function getKeys(obj) {
    var keys = [];
    iterate(obj, function (oVal, oKey) { keys.push(oKey) });
    return keys;
  }

  function iterate(iterable, callback) {
    for (var key in iterable) {
      if (key === 'length' || key === 'prototype' || !Object.prototype.hasOwnProperty.call(iterable, key)) continue;
      callback(iterable[key], key, iterable);
    }
  }


The Object/Script:

var obj = {
    "set1": {
                "subSet1": {
                    "val1": "",
                    "val2": "",
                    "val3": ""
                },
                "subSet2": {
                    "val1": "",
                    "val2": "",
                    "val3": ""
                }
            }
            ...
    }
var arr = [];

Object.keys(obj["set1"]).forEach(function(key) {
   arr.push(obj["set1"][key][val1]);   
});

after some testing i can tell that the problem is: the for...in statement does not work on mobile.

since it's impossible(?) to debug properly on mobile, there's no additional information i could give you. (error messages or sth)

Do you guys have a simple workaround?

tl/dr: Iterate over Object keys and fill an array with the key-names without the use of the for...in statement


edit1: just to complete things.. This is working on PC but not on mobile

    var testObj = {"a":"aa", "b":"bb", "c":"cc"};

    for (var keys in testObj) {
        app.alert(keys)
    }

    for each (var keys in testObj) {
        // not working mobile either
    }


since the DropDownLists aren't that huge and i need to get stuff done, i'll stick with manually creating the arrays i need, for now. Still curious though.


Solution

  • It's not possible with Adobe Reader Mobile using Acrobat JavaScript. Populating comboboxes (DropDowns) and listboxes is done using the Field.setItems() method which isn't available in Reader Mobile.

    For example, on Desktop versions, the following code will populate the "StateBox" field with the values in the array. The first item in the inner array is the user value (presented in the UI) and the second is the export value (the value exported when the data is submitted).

    var c = this.getField("StateBox");    
    c.setItems([["California", "CA"],["Massachusetts", "MA"], ["Arizona", "AZ"]]);
    

    The same code simply fails on mobile without presenting an error.