/ Id-Extras Forum / FormMaker Pro – Combo Box Export Values

  • Author
  • #6162 Reply
    Ryan G
    Participant

      This is more of an InDesign issue, as it does not support adding export values for the list item entries within an combo box. I don’t see any functionality within FormMaker that compensates for this.

      Currently I would still have to edit the PDF form within Acrobat to enter values for each drop down item every time I export the PDF.

      Does anyone know of a script that I could embed in actions for each combo box that would just automatically populate the values (or entries and values) as soon as the box was accessed?

      I don’t know enough JS to create from scratch, but can tweak code that is close. I haven’t found anything like this in my search yet.

      Thanks for your thoughts



      Testing out FormMaker and so far this has been exactly what I have been searching for!

      #6290 Reply
      ~~Ariel~~
      Participant

        Hi Ryan,
        Excellent question!
        You’re right that this is an InDesign omission. But then, when it comes to forms, InDesign is very weak, which is exactly what FormMaker is there to help with.
        As you have found, there is no direct way of adding values to combo box items even with FormMaker.
        But there’s an excellent workaround which I will describe, which I think you’ll find is actually almost as easy.
        The trick is to use FormMaker to add a “document” Javascript to the form. Document scripts are run whenever the form is opened in Acrobat Reader.
        But even better for our purposes, document Javascripts are run when you run the FormMaker command on the form in Acrobat. Which is something you have to do anyway.
        So, what we’re going to do is to write a document Javascript that will populate ALL your combo boxes with both item names and their corresponding values. This is very easy to do, and I’ll give an example further down.
        Once you’ve added this document script in InDesign, it will be there forever (for that document) so you need only do this once (of course, you can modify it as needed if changes need to be made to the form.)
        You will then export to interactive PDF as usual and run the FormMaker command as usual. Doing so will invoke the document Javascript, and you’ll find that all the combo boxes are populated as needed.
        Now you can save the PDF and distribute it to end users.
        In fact, before saving the PDF, you might want to take one extra step – to delete the (now unneeded) document Javascript from the PDF. There’s no reason to distribute the PDF with that doc script included, since we are the ones who needed it, not the end user. (The combo boxes are already populated with items and their values, and that’s all the doc script is needed for.)

        Here’s a sample Javascript that you can tweak to add items and values to combo boxes. You might even find that it’s easier to add the items this way than to use InDesign’s slightly clunky user interface for adding one item at a time.
        The script assumes that you have an InDesign document open with 2 combo boxes in it, called “Combo Box 1” and “Combo Box 2”.

        Code:

        c = this.getField("Combo Box 1");
        c.setItems([["California", "CA"], ["Massachusetts", "MA"], ["Arizona", "AZ"]]);
        c = this.getField("Combo Box 2");
        c.setItems([["Apples", "100"], ["Pears", "200"], ["Oranges", "300"]]);

        The basic idea should be clear: We’re using the “setItems” command to add items and their values to each combo box. The items and their values are provided as a set of small 2-element arrays inside one larger array.

        I’m also attaching a PDF that shows the end result. This PDF includes the document Javascript, although, as mentioned, it makes more sense to delete it from the PDF before saving and distributing it.

        Hope that helps! If anything is unclear or if you have any other questions, post back.

        Thanks,
        Ariel

        #6291 Reply
        Ryan G
        Participant

          This is excellent!

          I was able to do some testing with it Friday and will do some further reviewing this week.

          -Ryan

          #6292 Reply
          ~~Ariel~~
          Participant

            Great, I think it’s a pretty workable solution! If you find any issues, please post back.

            Thanks,
            Ariel

            #7086 Reply
            Keltexan
            Participant

              I have found and used a script called “Combo Mambo,” written by Chuck Weger. You can set up a list in a text file in Notepad or Notepad ++ and import the list into a combo box by running the script in InDesign. Below is a copy of the script with instructions on how to load the script into InDesign.

              #target InDesign
              // A script to fill in the choice list of a listbox or combobox in InDesign CS6, given a text file on disk.
              // Written by Chuck Weger <cweger@elara.com> for Sandee Cohen at the NYC InDesign Users Group, September 13, 2012
              // Updated by Chuck Weger 9/14/12 to filter for ONLY plain text files.
              // Updated by Chuck Weger 1/16/14 to work with InDesign CC
              
              // Copyright © 2012, Chuck Weger
              // This script may be freely distributed, copied, repurposed, chopped, diced, sliced, etc. But I would appreciate attribution.
              
              // USAGE:
              // 1. In InDesign, select (using the Selection Tool) a Combo Box or List Box
              // 2. Run this script
              // 3. When prompted, select a plain text file that contains the text you want in the list or combo box
              // 4. There is no step 4.
              
              if (app.selection.length) {
              var s = app.selection[0];
              if (s.constructor.name == "ComboBox" || s.constructor.name == "ListBox") { // avoid dealing with objects we can't process
              var theList = getTheList();
              if (theList) {
              if (theList.length) {
              s.choiceList = theList;
              }
              else {
              alert("There was a problem reading this text file. Sorry.");
              }
              }
              }
              else {
              alert("Please choose a ComboBox or Listbox with the direct selection tool first.");
              }
              }
              else {
              alert("Please choose a ComboBox or Listbox with the direct selection tool first.");
              }
              
              function getTheList() {
              // ask the user for a plain text file, then read that file in and split it up into lines
              var theList = [];
              var theFile = getOneTextFile("Please select a plain text file.");
              if (theFile) {
              if (theFile.open("r")) {
              var theListStr = theFile.read();
              theFile.close();
              theList = theListStr.split("\n"); // somehow this magically works cross-platform, even though it shouldn't!
              }
              }
              else { // user canceled the Open dialog
              theList = null;
              }
              return theList;
              }
              
              function getOneTextFile(prompt) {
              // returns a file object that points to a text (.txt) file
              var myFile = null;
              // set the file filter; this is different depending upon the platform
              if ($.os.indexOf("Mac") >= 0) { // this is running on a Mac
              var filter = filterTextFiles;
              }
              else {
              var filter = "Text files:*.txt"
              }
              var myFile = File.openDialog(prompt, filter);
              return myFile;
              }
              
              function filterTextFiles(f) {
              // a file filter, used for Mac OS X only
              var suffix = f.name.substr(f.name.length - 4).toUpperCase();
              if (suffix == ".TXT" || f.constructor.name == "Folder") {
              return true;
              }
              else {
              return false;
              }
              }

               

              #7679 Reply
              Ariel
              Keymaster

                Just to update this old thread: It is now possible, with FormMaker version 4.0, to add export values as part of the basic FormMaker UI. It is also possible to add a whole bunch of list items and their associated export values at once  (batch import):

              Viewing 6 posts - 1 through 6 (of 6 total)

              Tagged: 

              Reply To: Reply #6292 in FormMaker Pro – Combo Box Export Values
              Your information: