1

I need to pre-fill a dynamic PDF's fields so my users can edit it and submit back.

I am using Adobe ColdFusion CFPDFFORM tag that can load XML data into a PDF and make a new populated PDF. Unfortunately it also clears <xfa:datasets> tag, it completely empties it out! So all dropdownlists binded to datasets do not work. This is the code for binding one of them:

<bindItems ref="xfa.datasets.LOVFile.LOV.PreferenceLanguageList.PreferenceLanguage[*]" labelRef="$" valueRef="lic"/>

Since I have no control on how CFPDFFORM tag works, I came up with a workaround. Using LiveCycle Designer for codding, I store whatever data there is in <xfa:datasets> into a variable and load it to datasets at form::initialize.

This seems to load datasets fine, just like how they were before cfpdform messed them up. After loadXML() call , I can read the datasets and get identical results as in the original PDF with its datasets tag full of XML data.

form1::initialize - (JavaScript, client)
//xfa.host.messageBox("loading xml to datasets");
xfa.datasets.nodes.namedItem("LOVFile").loadXML(LOVFile_var.value,0,1);
Page1.Header.debug.rawValue = xfa.datasets.LOVFile.LOV.PreferenceLanguageList.resolveNode("PreferenceLanguage[2]").value;

The problem is down down lists still don't work, they have no item to show. Somehow their binding call to datasets does not refresh?

Is there anything else I should do after loadXML() ? LiveCycle reference for bindItems says "The links between the list items and the referenced data are active. Any change to the data causes an immediate update to the list items."

Any help or point to the right direction is greatly appreciated.

UPDATE:

using azathoth's answer I can add item to a dropdownlist using data from the newly loaded datasets (after loadXml() call).

var oEyeColors = xfa.datasets.LOVFile.LOV.resolveNode("EyeColorList");
var numberOfNodes = oEyeColors.nodes.length;       

var thisValue = "";

for (var i=0; i < numberOfNodes ; i++){
    thisValue  = oEyeColors.nodes.item(i).value;
    if(thisValue == null){
        thisValue = "";
    }
    xfa.resolveNode("Page1.eyeColorDropDownList").addItem(thisValue.toString());

}

This works but is not the solution I am looking for. There must be a JavaScript way to set bindItems of a dropdown.

Seeker
  • 1,250
  • 1
  • 16
  • 23

2 Answers2

2

I do what you specify with this code:

xfa.datasets.loadXML(LOVFile_var.rawValue, false, false); 
xfa.datasets.saveXML();                                 
var yourXML = xfa.datasets.resolveNode("yourXMLRootNodeName");
var numberOfNodes = yourXML.nodes.length;       

for (var i=0; i < numberOfNodes ; i++)
    yourDropDown.addItem(yourXML.nodes.item(i).nodes.item(1).value); // this can change according to what you retrieve in your xml  

Tell me if it worked for you

azathoth
  • 573
  • 2
  • 6
  • 18
  • Thx this helps for sure. But I want to keep it as the last resort since there are lots of dropdownlists in the form and some are changed as the user fills out the form. I had to make a few changes to make it work. I updated the post. – Seeker Aug 02 '11 at 18:21
  • I am still looking for a way to bind datasets to dropdownlists after datasets are updated. – Seeker Aug 02 '11 at 18:21
  • you can use a script object so that it will populate any dropdown with a certain dataset, with something like: `function populateDropDown(dropdown, datasetName)` – azathoth Aug 03 '11 at 14:46
0

perhaps this is what you're looking for?

Pre-populating dropdown lists in dynamic PDF forms from a back-end data source using LiveCycle ES2.5

http://www.adobe.com/devnet/livecycle/articles/prepopulating-dropdown-lists.html

azathoth
  • 573
  • 2
  • 6
  • 18