Tag Info

Hot answers tagged

17

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


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


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


11

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[ ...


11

Just like Albert I recommend using the second argument of Dynamic. Furthermore I recommend that you embrace the first A in AJAX, which stands for "asynchronous", so the kernel isn't busy while it collects the data (this might be why some change events are lost with your code). You can see how well the second argument of Dynamic works with this example: ...


10

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


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


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

I think the standard way to do this is to use the second argument of Dynamic, e.g. like so: With[{ getCompletion = Function[ Import[ "https://maps.googleapis.com/maps/api/geocode/json", "JSON", "RequestParameters" -> {"address" -> #} ] //. {{r__Rule} :> (Association[r])} ]}, DynamicModule[{ addr = "555 Mission St, San ...


8

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, ...


8

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, ...


8

The following code should fix the problem: CreatePalette[Pane[InputField["Enter a string"]], WindowFloating -> False, WindowClickSelect -> True]; But as we figured out it is not! I read all available information about WindowClickSelect and WindowFloating options in Mathematica documentation. I didn't find any notices that we can't use the options ...


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


8

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


8

Here is a basic example of how Mathematica code would be deployed. Get["http://exampledata.wolfram.com/Collatz.m"]; ?? Collatz Collatz[5] {5, 16, 8, 4, 2, 1} You can look into APIFunction that you access directly if you want to build an interface with HTML/Javascript, or if you want a simple interface running on Wolfram's cloud you can use ...


8

Support for the mechanism that makes the CDF browser plugin possible is being phased out, and the CDF player already does not work on the newest versions of Google Chrome. In light of this there is no better time than now to start mixing the Wolfram Language with HTML and Javascript. The concerns of using Wolfram Language as a backend/server language is no ...


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

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], ...


7

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, ...


7

Like Mike said in a comment, the key is to use the second argument of Dynamic. In this case I've built a function updateCurrencies which modifies a global variable currencies which holds an Association object with all the currency values in it. currencies = <| "USDollars" -> 0, "Euros" -> 0, "BritishPounds" -> 0, "SwedishKronor" ...


7

Here is some code I have for entering a 8 digit id number. So this is "out of the box" as is. If you enter more than 8 digits the extra characters are immediately deleted. You can modify to suit your purpose: InputField[Dynamic[id, (id = Which[ StringMatchQ[#, DigitCharacter ..] && StringLength[#] >= 8,StringTake[#, 8], ...


7

Response to edits: I don't know if I got all your points but this is the final update done by me :) v = {0.5, 0.05, 0.1, 0.15, 0.2}; active = Range@Length@v; update[i_, val_] := (v[[i]] = val; With[{range = DeleteCases[active, i]}, v[[range]] = (1 - val) Normalize[v[[range]], Total]]); updateCheckbox[i_, val_] := If[val, active = Join[active, ...


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

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


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

My humble contribution: (* Use this function to style list elements *) listItemStyle[item_] := Mouseover[#, Style[#, Background -> LightBlue]] &@ MouseAppearance[Framed[item], "LinkHand"]; (* This filters the list of data and returns a clickable list *) SetAttributes[autoComplete, HoldFirst]; autoComplete[s_, data_] := If[ StringLength[s] > 0, ...


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



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