Skip to main content
Inspiring
March 26, 2019
Answered

Entering text in new line

  • March 26, 2019
  • 1 reply
  • 1382 views

I made a dialog box that contains a text box field for employee comments, that later converts to a text layer.

Is it possible to enter text in a multiple lines on text box (because if I press ENTER, my dialog box closes)?

This topic has been closed for replies.
Correct answer r-bin

var d = new Window("dialog") 

 

var t1 = d.add("edittext", undefined, "", {multiline:true, scrollable:false}); 

t1.preferredSize = [300, 50]; 

 

var b = d.add("button", undefined, "OK"); 

 

d.defaultElement = null;

b.onClick = function () { activeDocument.activeLayer.textItem.contents = t1.text.replace(/\n/g, "\r"); } 

 

d.show(); 

1 reply

Legend
March 27, 2019

var d = new Window("dialog")

// for CC2018

var t1 = d.add("edittext", undefined, "", {multiline:true, scrollable:false});

t1.preferredSize = [300, 50];

// for CS6

var t2 = d.add("edittext", undefined, "");

t2.preferredSize = [300, 50];

t2.onEnterKey = function () { this.textselection += "\n"; }

d.add("button", undefined, "OK");

d.defaultElement = null; // to suppress OK button

d.show()

milevicAuthor
Inspiring
March 27, 2019

I am almost there It works, but as a result I got layer with whole text in one line. Is it possible to get text in text layer as it's entered into the dialog box.

r-binCorrect answer
Legend
March 27, 2019

var d = new Window("dialog") 

 

var t1 = d.add("edittext", undefined, "", {multiline:true, scrollable:false}); 

t1.preferredSize = [300, 50]; 

 

var b = d.add("button", undefined, "OK"); 

 

d.defaultElement = null;

b.onClick = function () { activeDocument.activeLayer.textItem.contents = t1.text.replace(/\n/g, "\r"); } 

 

d.show();