Skip to main content
mikee426461937464562
Participating Frequently
January 28, 2016
Answered

Can I re-open a dialog after a user clicks Ok button?

  • January 28, 2016
  • 2 replies
  • 1166 views

Hi all,

I would like to catch missing input (dropdown selection) in a scripted Illustrator dialog and return the user to the dialog as it was before he clicked ok.

Right now script logic goes along these lines:

var windowResource = "dialog{\

    text:'Batch Converter', \

    maximizeButton:true, \

    active:true\

    resizeable:true}";

  var aDialog = new Window(windowResource);

//add all sorts of ui elements

[...]

//show dialog

var returnValue = aDialog.show();

//user clicked ok

if (returnValue == 1) {

//check for user input

//->reopen dialog if something is missing

}

//user clicked cancel
else {

aDialog.close();

}

I don't really want to mess with custom event handlers so just going back to the original dialog seems the easiest and most user friendly way right now.

Is that even possible?

Cheers,

Mike

Correct answer Qwertyfly___

Another method I like is to disable the ok button until all requirements are met.

I just made some modifications to W_J_T's code to make it simple to see the differences

function test() { 

    var w = new Window("dialog", "Drop Down List"); 

    w.margins = 25; 

    var txt = w.add("statictext", undefined, "Select A Drop Down Item:"); 

    var dropArray = []; 

    for (var i = 1, l = 50; i < l; i++) { 

        dropArray.push("Drop Down List Item = " + i); 

    } 

    var dropList = w.add('dropdownlist', undefined, dropArray); 

    dropList.onChange = function() { 

        if(dropList){

            okBtn.enabled = true;

        }; 

    } 

    var okBtn = w.add('button', undefined, 'OK'); 

    okBtn.preferredSize = [200, 25];

    okBtn.enabled = false;

    okBtn.onClick = function() { 

            w.close();   

    } 

    w.show(); 

test();

2 replies

mikee426461937464562
Participating Frequently
January 29, 2016

Thanks, W_J_T and Qwertyfly - this helps a lot.

Should have actually thought about this myself.

I really like Qwertyfly's approach - don't let the user make the mistake in the first place.

re resource strings: the script originated some 7 years back - I'm still amazed how little I had to change over time to keep it working.

I'm currently modifying it in a lot of places to adjust it to changes in our workflow so I'll do some cleanup to those parts as well.

Best,

Mike

Inspiring
January 29, 2016

You're welcome. @Qwertyfly good call pointing that out.

Qwertyfly's approach - don't let the user make the mistake in the first place.

Yeah that's the more brute force - call to action.

Inspiring
January 28, 2016

Hi Mike,

  • catch missing input (drop down selection) and return the user to the dialog as it was before he clicked ok

You could re-open the dialog, but perhaps a better way would be just add some conditional logic to ensure all required user input has been added before proceeding. This way you don't have to possibly eradicate the other possible inputs by the user via closing and re-opening the window (unless you are saving parameter data already), it may retain it however.

Basic example: (Sorry not a fan of the resource string approach) ;-)

function test() {

    var w = new Window("dialog", "Drop Down List");

    w.margins = 25;

    var txt = w.add("statictext", undefined, "Select A Drop Down Item:");

    var dropArray = [];

    for (var i = 1, l = 50; i < l; i++) {

        dropArray.push("Drop Down List Item = " + i);

    }

    var dropList = w.add('dropdownlist', undefined, dropArray);

    dropList.onChange = function() {

        alert(dropList.selection.index + 1);

    }

    var okBtn = w.add('button', undefined, 'OK');

    okBtn.preferredSize = [200, 25];

    okBtn.onClick = function() {

        if (dropList.selection == undefined) {

            alert("ERROR\n'Drop Down List' still needs user input.");

        } else {

            w.close();

        }

    }

    w.show();

}

test();

Hope it helps your efforts.

Qwertyfly___
Qwertyfly___Correct answer
Legend
January 28, 2016

Another method I like is to disable the ok button until all requirements are met.

I just made some modifications to W_J_T's code to make it simple to see the differences

function test() { 

    var w = new Window("dialog", "Drop Down List"); 

    w.margins = 25; 

    var txt = w.add("statictext", undefined, "Select A Drop Down Item:"); 

    var dropArray = []; 

    for (var i = 1, l = 50; i < l; i++) { 

        dropArray.push("Drop Down List Item = " + i); 

    } 

    var dropList = w.add('dropdownlist', undefined, dropArray); 

    dropList.onChange = function() { 

        if(dropList){

            okBtn.enabled = true;

        }; 

    } 

    var okBtn = w.add('button', undefined, 'OK'); 

    okBtn.preferredSize = [200, 25];

    okBtn.enabled = false;

    okBtn.onClick = function() { 

            w.close();   

    } 

    w.show(); 

test();