# How can I fix this output?

The following segment of code is part of a project I am making and therefore I cannot show all the code. I hope the one below is enough.

The input is

Panel[DynamicModule[var, InputField[Dynamic[var], String]]]


while the output is

which in thid case displays DynamicModule[var,] that is not wanted. How would I fix this? I want to add that I want to keep the same functions used above.

Also, how would I put text next to the input field? Thank you.

• Use DynamicModule[{var}, ...] instead. – Carl Woll Jan 8 '18 at 19:08
• @CarlWoll this does seem to fix the problem but now when I enter a word and press enter nothing happens. Instead, it should evaluate the command as it did without this fix. – DMH16 Jan 8 '18 at 19:15
• @DMH16 It still does but if you need the variable outside of DynamicModule you will need an assignment in Dynamic[globVar = var] – Coolwater Jan 8 '18 at 19:19
• @DMH16 Dynamic[var, (var = globVar = #) &] works, but I don't understand why the Dynamic[globVar = var] doesn't :/ – Coolwater Jan 8 '18 at 19:50
• @Coolwater because Set is not Flat and (x = y) = 5 is not the same as x = y = 5 – Kuba Jan 8 '18 at 20:23

Panel[DynamicModule[{var = "Type here"},
InputField[Dynamic[var], String]]]


or, for a version with a variable text that can be inspected

Panel[DynamicModule[{var = "Type here"},
InputField[Dynamic[var, (text = var = #) &], String],
Initialization :> (text = var)]]


I can't seem to add a comment above. Try this... Also, note that Modules and Dynamic Modules are like Objects and the variables such as 'var' is only valid inside the Module

Panel[DynamicModule[{var}, Grid[{{InputField[Dynamic[var], String],Dynamic[var]}}]]]


We can just include Panel inside the Module

DynamicModule[{var}, Panel[InputField[Dynamic[var], String],Dynamic[var]]]


All you do is tab whenever you fill the input field