开发者

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 开发者_如何学CReturn. I just want a simple text input field.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜