3 Replies Latest reply on Apr 14, 2011 11:55 AM by John Hawkinson

    Multiline Prompt Window

    Creaticious

      Hey all,


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

      iterate over them?

       

      thx!

        • 1. Re: Multiline Prompt Window
          Peter Kahrel Adobe Community Professional & MVP

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

          • 2. Re: Multiline Prompt Window
            Creaticious Level 1

            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 ??

            • 3. Re: Multiline Prompt Window
              John Hawkinson Level 5
              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");