Copy link to clipboard
Copied
I need to code a listbox that is dependent on items in a text box. Each item in my text box, separated by commas, has an associated form that I need to add to the listbox. E.g. Text box = Lifting Operations, Plugs, Hot Work then List Box = Critical Lift Form, Expandable Plug Form, Hot Work Permit. The user will choose the forms necessary for the job from the list box through an "ADD" button, which I've already created.
Copy link to clipboard
Copied
So the sequence is
1) user types comma separated list of items in a text field.
2) text field is parsed and items are mapped into different text entries placed in a list field.
3) user selects item from list, which somehow adds a form to the PDF?
is this correct? If so then then you can create a translation object for mapping items from the text field into the list field.
Please explain the specific issues that need to be solved.
But why have the user enter a comma separated list? Why not have them select items off of another list? so they don't screw up typing in the text?
Here's some article that explain how to program lists.
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
https://acrobatusers.com/tutorials/list_and_combo_in_lc/
Copy link to clipboard
Copied
Thank you for the reply!
For step 1 above) The user is actually selecting Hazards from a listbox, multiple items, and clicking an ADD button, which is populating a text box, with each hazard separated by commas, (this is so they all show upon printing instead of items moving into another listbox where all selected items may/may not be visible).
2) Based on the items (hazards) popilating the text box, I'd like all the forms for those hazards to populate a new list box. (This is the JavaScript I'm having trouble with)
3) Users will then select the applicable forms necessary, not all forms per hazard may apply, but again they may need to select multiple forms, which they will then select and ADD to another text box (so when they print, all forms necessary will be visible, separated by commas, instead of going into another listbox that may not have enough room to show/print all selected items) I have steps 1 and 3 ADD buttons coded, I just don't know how to get the (hazards) text box items to show associated forms into the step 3 (hazards forms) listbox.
Copy link to clipboard
Copied
Ok, so the requirement is to map "hazard" names selected from one multiselect listbox, into the "Form" names listbox. So you need a mapping between those two things, "hazard" names to "form" names. An easy way to do this is to make the form name the export value of the Hazard list. Here's a script that makes a list of items from the export values of the selected items in the Hazard list. You'll need to change the field names to match the ones on your form
// initialize an empty form list
var aFormList = [];
// Walk selected hazard items to get the associated form items from the export value
var oLstFld = this.getField("HazardList");
var aSel = oLstFld.currentValueIndices;
if(typeof(aSel) == "number"){
if(aSel >= 0)
aSel = [aSel];
else
aSel = [];
}
aSel.forEach(nIdx=>aFormList.push(oLstFld.getItemAt(nIdx, true)));
// Set items in form list
this.getField("FormList").setItems(aFormList);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The form contains a confusing set of actions, many of which work at cross purposes and generate errors. The first thing to do is to delete most of the code you've entered and start over.
Get rid of the "Add" button and just use the calculate script to set the comma separated text.
Next, there needs to be a mapping between the hazards and the forms.
In the current form, the "populatelistbox" function is providing the mapping. This function should be defined in a document level script so that it is visible to all scripts in the document. Right now it can't be seen outside the context where it is defined. The function should then be called every time there is a change in selection.
One of the challenges of scripting this type of behavior is mantaining consistency between the selections in the "hazard" lists, the entries in the "forms" list. The best approach to maintaining consistency is to recreate the entire form list on each change in hazard selection. So, use the "list.setItems()" function, as shown in the code I posted. There is no such thing as an "list.addItem()" functio
Copy link to clipboard
Copied
Thank you!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more