Tag Info

Hot answers tagged

16

Ah, figured it out: Panel @ DynamicModule[{input = ""}, Column[{TextCell["Enter your text here:"], EventHandler[ InputField[Dynamic[input], String, ContinuousAction -> True, FieldSize -> {40, 7}], "ReturnKeyDown" :> FrontEndExecute[{NotebookWrite[InputNotebook[], "\n", After]}] ], Dynamic@InputForm[input]}]]


15

I thought this was undocumented, but actually it just seems to be obscure. The documentation for ControlType mentions, under the "More Information" section, Arbitrary controls can be set up in Manipulate by giving control specifications of the form {u, func}. So, Manipulate[InputForm[col], {col, "AB", InputField[#, String] &}] gives (with a ...


14

I wouldn't call it a bug, and is in fact, the expected behaviour (at least, I expect it). Look at it this way — when you input a String or a Number, Mathematica doesn't need to interpret it/evaluate it and can readily display the value dynamically. On the other hand, with an Expression, it needs to know that you have finished entering the expression and it ...


14

EDIT--- The code was updated to include anti-cheating filter to address important issues raised by @Jens in comments (thanks). More filters can be added to exclude other type of cheating. ---EDIT I was teaching physics and math for many years and consider this to be a very important question. I would say Mathematica is very well equipped for this type of ...


12

Test function: dateCheck[date_String] := StringMatchQ[date, DatePattern[{"Day", ":", "Month", ":", "Year"}]] Input field: InputField[Dynamic[date,If[TrueQ[dateCheck[#]], date = #, date = ""] &], String] This gives you a variable date that is a string of the form dd:mm:yyyy. If you want to convert it to a list or a number then e.g. ...


10

Here is a proof-of-concept of something that you can build upon to create such homework assignments. First, a helper function to check the correct answer and display the result. I'm only checking for accuracy to the third decimal, but you can tweak that as you wish. ClearAll[checkAnswer] checkAnswer[Null, _] := "" checkAnswer[ans_, correct_] := If[ ...


9

Here is a widget which I constructed some time ago for my purposes. This is an InputField as well, but it operates on boxes, and as a bonus, the standard syntax highlighting works inside it: ClearAll[codeInputField]; Attributes[codeInputField] = {HoldFirst}; Options[codeInputField] = { BaseStyle -> {FontSize -> 14, FontWeight -> Plain, ...


9

nrows = 3; ncols = 4; t = ConstantArray[0, {nrows, ncols}]; it = Table[With[{i = i, j = j}, InputField[Dynamic[t[[i, j]]]]], {i,nrows}, {j, ncols}]; Dynamic[TableView[it]] Another dynamic view to show it works: Transpose[t] // TableView // Dynamic (the Transpose here just used to show it actively uses the input). Please note that I used the ...


8

As I mentioned in my comment to the question, I am quite fascinated by the idea of testing free-form input by numerical means similar to what the AcroTeX bundle has been able to do for a long time. This idea differs quite fundamentally from Vitaiy's suggestion, so I have tried to make it work in Mathematica. I will suspend discussion of the crucial ...


8

You can get custom colors and rounded corners by adding a custom frame to a frameless InputField. The following code approximates the look of Wolfram Alpha's input field: With[{opts = {FrameMargins -> 0, ImageMargins -> 0}}, Framed[ Framed[InputField[, ImageSize -> {500, 25}, Appearance -> "Frameless"], FrameStyle -> ...


7

You could do something like InputField[Dynamic[d, (d = HoldForm @@ #) &], Hold[Expression]] This will wrap the expression typed into the input field in HoldForm.


7

Assign your input in DialogReturn, e.g. to a variable return. Apart from from this, and omitting your Dynamic@x at the end, your code is unchanged: DynamicForm[row_, col_] := DynamicModule[{x = ConstantArray[0, {row, col}], a}, a = {Column[(Row[#] & /@ Table[With[{i = i, j = j}, InputField[Dynamic[x[[i, j]]], Number, ...


7

If you want the evaluation to halt until the Dialog returns you can get your code working very simply: DynamicForm[row_, col_] := DialogInput[{x = ConstantArray[0, {row, col}], a}, Column[Flatten@{{Column[(Row[#] & /@ Table[With[{i = i, j = j}, InputField[Dynamic[x[[i, j]]], Number, FieldSize -> Tiny]], {i, 1, row}, {j, 1, ...


7

Here is one solution:- CreateWindow[DialogNotebook[{TextCell["Number of Stations: "], PopupMenu[Dynamic[ns, ( ns = #; (* set default values *) Function[n, (x[n] = 0)] /@ Range[ns]; col = Column[InputField[Dynamic[x[#]]] & /@ Range[ns]]) &], Range[2, 8]], TextCell["Sound Frequency (kHz): "], Dynamic[col], ...


6

If applying a new stylesheet doesn't change the appearance then it looks like the styling is local to each cell. If you have a look at the underlying expression of some of these input cells by going to the menu and choosing Cell > Show Expression you should see some StyleBoxes, as per this example using your code that you have supplied: So if it is the ...


6

Your code can be made much simpler as such... xlData = {{1, "a", "b", "c"}, {2, "d", "e", "f"}}; Grid@Table[ With[{i = i, j = j}, InputField[Dynamic[xlData[[i, j]]], FieldSize -> {4, 1}]], {i, 1, Length[xlData]}, {j,1,Length[xlData[[1]]]}] As you change values, it can be monitored by: Dynamic[xlData] As written, the code keeps xlData with ...


6

Perhaps something like this? text = ""; EventHandler[ InputField[Dynamic@text, String, ContinuousAction -> True], {"ReturnKeyDown" :> Paste["\n"]} ]


5

Since you said you wanted text input containing subscripts, superscripts, etc, it sounds like you just want Mathematica's box language: InputField[Dynamic[d], Boxes] Now d is boxes, such as In[39]:= FullForm[d] Out[39]//FullForm=SuperscriptBox["a","b"] You can convert them to expressions with MakeExpression or ToExpression, or interpret them any ...


5

Perhaps this slightly modified version of your code is closer to what you want. Remember, Ctrl+J, not Enter, to start a new line. DynamicModule[{data = "some\ndata"}, Column[{ Framed[ Pane[InputField[Dynamic@data, String, ContinuousAction -> True, Appearance -> None, FieldSize -> {Automatic, {1, Infinity}}], ...


5

I also took a crack at this. I think I made it look pretty close to the jquery example you posted. Figuring out how to move the insertion point to the end of the word once a suggestion is selected was a bit of a struggle. As a result, there's a DynamicWrapper in there that may be unstable. Input is the list of possible values from which you'd like to draw ...


5

Update. Thanks to Eldo, Dynamic is needed outside the InputField. DynamicModule[{a = 1, b = 20, fuc = "1"}, Deploy[Style[Panel[Grid[Transpose[ { {"Input Format", "Value"}, {PopupMenu[Dynamic[fuc], {"1", "2"}], Dynamic@InputField[ If[fuc == "1", a, b], Number, Enabled -> Dynamic[fuc == "1"] ...


4

I can't give a complete testable answer because you haven't defined e.g. myInputs but it sounds like what you need is to test the field values and make sure that they meet certain criteria before processing. Therefore something along these lines should do the job (If you provide more complete information I can try for a better answer): ...


4

Maybe overkill but it was educational to try: DynamicModule[{}, EventHandler[ Overlay[{ Dynamic@Framed[ Row[{Style[x, Transparent, 15, Bold], Style[rest, GrayLevel@.6, 15, Bold]}], ImageSize -> {280, 30}, Alignment -> Top, FrameMargins -> {{5, 0}, {0, 1}}], InputField[Dynamic@x, String, BaseStyle ...


4

This seems to work for me, is it what you need? InputField[Dynamic[h2, If[NumericQ[#], h2 = Round[#, 0.001], h2 = h2] &]]


4

Note: This appears to really slowly in M9, although it works well in M8. It probably is better to use teedr's until it can be figured out what is causing the slow speeds. The following seems to work pretty well. I wrapped the options in a Pane and Framed so the entire row is clickable. ClearAll[AutoInputField]; SetAttributes[AutoInputField, ...


4

Edit: Now works with either Enter or Tab, thanks to ybeltukov. Now simplified with your own idea to use Null as the Dynamic variable: list = {}; Dynamic[list] Grid@{{InputField[Dynamic[Null, AppendTo[list, #] &]], Button["Reset", list = {}]}} Type expressions, then press Enter, and watch them appear in list (as viewed with Dynamic). Note that with ...


4

For version 9 or above, one can use CellPrint (or simply Print, as it is a specific case of CellPrint) which does not move the selection and thus preserves the focus on the InputField. EventHandler[InputField["", String], {"ReturnKeyDown" :> CellPrint[Cell["test", "Output"]]} ] Since the above code only works in v9, here is an equivalent with ...


4

This Answer is based upon Kuba's comment above regarding two InputFields, so credit should go to him for the idea, this is just an implementation. However, the problem interested me because I have a similar issue to solve regarding entering units into answers, and this question and Kuba's comment made me think of a related solution to that. One can use ...


4

There are a number of issues here: There is no need to wrap Dynamic around the inner variables of the final input field expression. Indeed, it is harmful as Dynamic is purely a user interface element and acts as a holding wrapper in any other context (like an arithmetic expression). The use of Function in the output expression will cause the variables x ...


4

I'll show you hoe to do it for a 3 x 3 matrix of values. You should be able to extend to 3 x 12 without much trouble First do some initialization. headers = {"Jan", "Feb", "Mar"}; rowLbls = {" ", "Tmax", "Tmed", "Tmin"}; valTbl = ConstantArray[0, {3, 3}]; Next build the spreadsheet. MapThread[Prepend, { Prepend[ ...



Only top voted, non community-wiki answers of a minimum length are eligible