Skip to main content
Inspiring
March 9, 2020
Question

setting up a dialog box to get multiple page numbers and assign variables

  • March 9, 2020
  • 2 replies
  • 440 views

 

I'm setting up an input dialog box to get page numbers that eventually will be output to pdf's. Currently I have set up 4 boxes to get those variables but I'm wondering if there is a better way, a more flexible way? Maybe Someone might need 6 pages or 10. Does anyone know how this might be accomplished?

 

var myInputGroup3 = myWindow.add("group");
        myInputGroup3.alignment="right";
            myInputGroup3.add("statictext", undefined, "PAGE NUMBERS:");
            var myText3=myInputGroup3.add("edittext", undefined, "1");
                myText3.characters=14;
            var myText3b=myInputGroup3.add("edittext", undefined, "4-5");
                myText3b.characters=13;
            var myText3c=myInputGroup3.add("edittext", undefined, "8");
                myText3c.characters=13;
            var myText3d=myInputGroup3.add("edittext", undefined, "10");
                myText3d.characters=13;


pageNumber = (myText3.text);
pageNumberb = (myText3b.text);
pageNumberc = (myText3c.text);
pageNumberd = (myText3d.text);

 

This topic has been closed for replies.

2 replies

Inspiring
March 9, 2020

Use a repeat loop to set up the input fields in the dialog box. Here are the steps:

1. Use a simple dialog to get the number of pages ("entries"). Pass this value to a function.
2. Inside the function: Set up an empty array for the entries (eList). Create a custom dialog with a single column.
3. Inside the column use a repeat loop to create a border panel (1 for each page)
4. Inside each border panel create a dialog column to hold the dialog rows.
5. In creating each border panel input field, assign a variable to capture the field's contents.
6. Create an associative array (name value pairs) for the border panel's field results. Add the associative array to the "entries" array.
7. The associative array for each border panel will look similar to:
[panelName:pName, pageName:edit contents of field1, numChar:edit contents of field2]
8. If user does not cancel the dialog, the "entries" array is passed back to the main function.

 

Hope this helps

brian_p_dts
Community Expert
Community Expert
March 9, 2020

Lots of ways to skin this cat, depending on your ultimate needs. One solution could be to just use one text range field, then parse that field. You'd have to validate the input, of course. 

var myText3=myInputGroup3.add("edittext", undefined, "Insert range here");
var pages = [];
var splitText = myText3.split(",");
for (var i = 0; i < splitText.length; i++) {
    splitText[i] = splitText[i].replace(/ +/,"");
    if (splitText[i].match(/\d{1,}-\d{1,}/gi)) {
       //this is a range, like 4-5. You can then write some code to parse out the individual pages then push to the pages array
    }
    else if (isNaN(splitText[i])) {
        $.writeln((splitText[i] + "is not a valid input"));
    }
    else {
        pages.push(splitText[i]);
    }
}