Skip to main content
April 14, 2011
Question

Multiline Prompt Window

  • April 14, 2011
  • 2 replies
  • 743 views

Hey all,


is there a simple way to get an prompt for multiple lines of text and later

iterate over them?

thx!

This topic has been closed for replies.

2 replies

John Hawkinson
Inspiring
April 14, 2011
is there a simple way to get an prompt for multiple lines of text and later

iterate over them?

No, it's not simple. Splitting the return value on newlines and iterating over them is left as an exercise to the reader:

function mprompt(message, preset) {
    var
        messageLength = message?message.length:0,
        d = new Window(
'dialog { m: StaticText { characters: '+messageLength+'},'+
' i: EditText { active: true, characters: 80,'+
'   properties: { multiline: true } },'+
'b: Group { c: Button { text: "Cancel" }, '+
'  o: Button { text: "OK" } }'+
'}');
    if (message) { d.m.text = message; }
    if (preset) { d.i.text = preset; }
    // We need to define our own event handler to get

    // newline characters
    // into the multiline field when you hit Return
    d.addEventListener("keydown", function(e) {
        if (e.keyName==='Enter') { d.i.textselection+='\n'; }
        });
    // Size the input box 4 lines high, unless we know better
    if (!preset) {

        d.i.preferredSize = [ -1, d.i.preferredSize[1]*4 ];

    }
    // We cannot allow the default event handler to capture Enter
    d.defaultElement = null;
    // We need our own handler to close the window.
    d.b.o.onClick = function() { d.close(1); };
    if (d.show()===1) {
        return d.i.text;
    } else {
        return null;
    }
}

mprompt("Multi-line prompt");

Peter Kahrel
Community Expert
Community Expert
April 14, 2011

alert ("Line 1\rLine 2\rLine 3\etc.");

April 14, 2011

Hi Peter,

thx for ur answer but i ment an text input prompt. so that the user gets a little textarea to type some lines...

Maybe u've got an idea for that ??