Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to use an InputField with a generic dynamic variable (not restricted to be Number or String or whatsever) and I don't want to see the quotation marks in the case the input is a string. Here is an example

z="";
InputField[Dynamic[z]]

I know the Cell's option ShowStringCharacter but here doesn't work, for instance see

z = "";
Panel[Column[{Style[InputField[Dynamic[z]], 
    ShowStringCharacters -> False], Spacer[5], 
   Row[{"This is the value of variable z", Spacer[5], Dynamic[z]}]}]]

and this one

z = "";
ExpressionCell[
 Panel[Column[{Style[InputField[Dynamic[z]], 
     ShowStringCharacters -> False], Spacer[5], 
    Row[{"This is the value of variable z", Spacer[5], 
      Dynamic[z]}]}]], ShowStringCharacters -> False]

Any suggestion? Thanks in advace, Roberto

share|improve this question
2  
Then how can the InputField distinguish what head has the input e.g. 123 a, should it be "123 a" or 123 a? –  Kuba Nov 16 '13 at 15:14
    
@Kuba, I know, and indeed I think the InputField behavior is correct, but ShowStringCharacter is just for that, I mean just for visualization. If you do z = "test"; ExpressionCell[z, "Text", ShowStringCharacters -> False] the quotation marks are not printed, however z is still a string. –  bobknight Nov 16 '13 at 15:22
    
but this is not an Input type Cell, try to edit it. –  Kuba Nov 16 '13 at 15:24
    
You are right, this is a different type of cell, the ExpressionCell generates a Cell with the value of the variable z and not the variable itself inside a Dynamic. Moreover, it uses InterpretationBox exactly to have the visualization different from the expression, that's the trick. And I guess this is not replicable inside a Dynamic object. Thanks anyhow. –  bobknight Nov 16 '13 at 15:53
1  
It's not a problem of Dynamic, cell types or a possbilities of MMA. The problem is that the behaviour you need is, as I showed earlier, ambigious. Clarify how Mathematica has to know when you enter a string or not and we can work on this. –  Kuba Nov 16 '13 at 16:14
show 1 more comment

1 Answer 1

May be this is what you are looking for. Calling Style before calling InputField, rather than after, seems to work.

z = "fox";
Panel[
  Column[{
    InputField[Style[Dynamic[z], ShowStringCharacters -> False]], 
    Spacer[5], 
    Row[{"This is the value of variable z: ", Spacer[5], Dynamic[z]
  }]}]]

panel.png

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.