javascriptextendscript

edittext not responsding .onClick (Extendscript)


Why is this not working?

...
var newFolder = inputGroup.add ("group");
var newIFolder = newFolder.add("edittext",[0, 0, 300, 20]);
var addButton =  newFolder.add ("button", undefined, "Add");


var closeButton = window.add ("button", undefined, "Close");

closeButton.onClick = function() {
    window.close();}

addButton.onClick = function() {
    return newIFolder.text;
    window.close();
    alert(newFolder.text);}
...

Nothing happens onClick, the window just remains open.

Perhaps it's because of the groupings, somehow. I'll try to move it on top level, while I wait.

Thanks in advance and best regards.

Edit: On top level no change :( Edit2: I've tried, but no change :(

var addButton =  window.add ("button", undefined, "Add", {name: "ok"});

Solution

  • Here is exactly the code I just tried and it works fine for me (InDesign 2022, Illustrator 2023, Photoshop 2023):

    var window = new Window ("dialog");
    // var newFolder = window.add ("group");
    var newIFolder = window.add ("edittext",[0, 0, 300, 20]);
    var addButton =  window.add ("button", undefined, "Add");
    var closeButton = window.add ("button", undefined, "Close");
    
    closeButton.onClick = function() {
        window.close();
    }
    
    addButton.onClick = function() {
        window.close();
        alert(newIFolder.text);
        return newIFolder.text; // <-- probably the problem was here
    }
    
    window.show();