Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple text input field accepting line breaks

Is there a simple way to get this to work?

text = "";
DialogInput[{TextCell["Try to type a text with linebreaks :-)"],
  InputField[Dynamic[text], String], 
  Button["Ok", DialogReturn[text]]}]

The problem is that InputField terminates after typing Return. I just want a simple text input field.

like image 357
phantomas1234 Avatar asked Aug 04 '11 18:08

phantomas1234


1 Answers

Thanks for the heads-up Leonid. Here is the code:

text = "";
DialogInput[{TextCell["Try to type a text with linebreaks :-)"], 
  InputField[Dynamic[text], String, FieldSize -> {30, 6}], 
  DefaultButton[DialogReturn[text]]}, 
 NotebookEventActions -> {"ReturnKeyDown" :> 
    FrontEndExecute[NotebookWrite[InputNotebook[], "\n"]]}]

The FrontEndExecute statement is a little simpler in this version.

Incidentally, to clear the default Return key action of NotebookEventActions you can use NotebookEventActions->{}. This can be useful to stop dialogs disappearing during input.

like image 52
Chris Degnen Avatar answered Sep 17 '22 14:09

Chris Degnen