Skip to main content
Participant
March 18, 2024
Question

Acrobat JavaScript for listbox populate dependent on text box items

  • March 18, 2024
  • 1 reply
  • 1082 views

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.

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
March 19, 2024

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/

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
March 19, 2024

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.

Participant
March 21, 2024

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);

 

 

 

 

 

 


I tried but what I have in the Action JavaScript for step 2 in the "Applicable Life Critical List" textBox for the first 2 cases isn't working to bring the forms options into the "Forms Options Per Hazards" listBox. Any help to this attachment is appreciated!