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.