0

I have created a CDF that has some InputFields in the middle of the text, for the reader to enter his own values.

Everything works fine on the CDF Player (8.0.3) except when the user, after changing a value inside a field, presses ENTER instead of: "Return" or "Tab" or "mouse selecting other field".

If he presses ENTER, the CDF player does exactly the same thing that Mathematica does: a line duplication, with eventually some internal cell structure showing in the middle.

All Mathematica users can easily avoid pressing ENTER, but the CDF Player users are most likely not aware of this ENTER/RETURN duality.

I've tried all the notebook options I could remember: deployed, editable, etc., with no success,

Another thing I remembered was to remove the ENTER action with the NotebookEventAction, but could not find how to do it: {"KeyDown", "Enter"}->Null ??? ; tried Enter, EnterKey, [EnterKey], etc, with no success.

Can someone help me to remove this Enter side effect from the CDF Payer?

Verbeia
  • 4,400
  • 2
  • 23
  • 44
P. Fonseca
  • 549
  • 4
  • 12
  • I think this has been answered here: http://stackoverflow.com/q/6946475/615464 – Sjoerd C. de Vries Aug 30 '11 at 22:12
  • @Sjoerd - not really. At least I cannot find from the mentioned post, how to isolate the ENTER, and not the RETURN, either to transform it into a RETURN, or to make it Null action. – P. Fonseca Aug 31 '11 at 07:30
  • Interesting enough, both the Panel and the Manipulate don't suffer from this behavior. I think the reason is because they are formatted exactly the same way, either when in an input cell, or in an output cell (they do get transformed into an input cell when Enter is pressed -> can see this by the cell bracket). So the questions are: how can I make all input cells look just like the output cells; or how can I block the automatic creation of a new input cell when the user ENTERs an output cell; or how can I block the simple creation of input cells in a notebook? – P. Fonseca Aug 31 '11 at 18:06

1 Answers1

2

This works well for numbers:

ExpressionCell[InputField[Dynamic[x], Number], Evaluatable -> False, 
 Background -> White]

For other input types shift-Enter creates a line-break.

Chris Degnen
  • 8,443
  • 2
  • 23
  • 40
  • This works fine for each cell. Thank you. Do you know of another way that makes the same behaviour for all the notebook? – P. Fonseca Aug 31 '11 at 07:32
  • I found the doc page for `ExpressionCell` a bit confusing. They never really explained _why_ and _when_ you would use this function. Almost every example I tried yielded the same (visual) result when `ExpressionCell` is removed. – Sjoerd C. de Vries Aug 31 '11 at 08:52
  • 2
    @ Fonseca. Not readily. NotebookEventActions doesn't register the Return+Shift, although UpArrow+Shift works. Example: x = 0; SetOptions[InputNotebook[], NotebookEventActions -> {"UpArrowKeyDown" :> If[CurrentValue["ShiftKey"], x++, x--], "ReturnKeyDown" :> If[CurrentValue["ShiftKey"], x++, x--]}]; Dynamic[x] – Chris Degnen Aug 31 '11 at 08:55
  • @ Sjoerd. If you look up the documentation on Evaluatable you will see why ExpressionCell's transparency is useful for adding modifiers. – Chris Degnen Aug 31 '11 at 09:32
  • @Chris - can't the shift+return/enter event be tracked so that we find out how Mathematica calls it? Like trying to find the event of a specific UI hardware. Have no idea if this is possible... – P. Fonseca Aug 31 '11 at 11:35
  • Interesting enough, both the Panel and the Manipulate don't suffer from this behavior. I think the reason is because they are formatted exactly the same way, either when in an input cell, or in an output cell (they do get transformed into an input cell when Enter is pressed -> can see this by the cell bracket). So the questions are: how can I make all input cells look just like the output cells; or how can I block the automatic creation of a new input cell when the user ENTERs an output cell; or how can I block the simple creation of input cells in a notebook? – P. Fonseca Aug 31 '11 at 12:35
  • 1
    @Fonseca The Documentation says: "`Evaluatable` is more often set for styles of cells than for individual cells". So you can modify at least the `"Output"` style for current Notebook using [`StyleDefinitions`](http://reference.wolfram.com/mathematica/ref/StyleDefinitions.html) and include options `Evaluatable->False,Editable->False` in it. You can also set `Editable->False` for notebook itself: `SetOptions[EvaluationNotebook[], Editable -> False]`. Now you can evaluate input cell in this Notebook but cannot modify them. – Alexey Popkov Sep 01 '11 at 07:42
  • 1
    @Fonseca See also Documentation for options `CellEditDuplicate`, `CellEditDuplicateMakesCopy` and `CellEvaluationDuplicate`. – Alexey Popkov Sep 01 '11 at 07:51
  • Tried CellEditDuplicate, CellEditDuplicateMakesCopy and CellEditDuplicate, all with no success. What is annoying in the Evaluatable solution is that the Enter no longer works at all. This isn't what a non Matematica user would expect. The user changes a value with the numpad, and instinctively presses the Enter key. If Evaluatable is set to False, nothing happens, and so, the user, that is sure he has pressed Enter is looking at values that aren't true. I thank you all for the very cleaver answers, but I’m still searching for a solution that will look and feel like a standard app. – P. Fonseca Sep 01 '11 at 12:06