I'm having trouble detecting when my InputForm supplied String variable has a value. After looking at:
How to compute values only if input fields are filled?
I tried a StringQ test:
Clear[foo]
foo[t_] := If [ StringQ[t], {t, "defined"}, {t, "undefined"} ]
DynamicModule[{symbol},
Column[{
Row[{"Text field:", InputField[Dynamic[symbol], String]}],
foo[ Dynamic[symbol] ]
} ]
]
Before the field is supplied this gives me what I expected:
but after keying the field, I see that my test hasn't worked:
Based on
How can I make sure all InputFields have values before processing a nb form?
I tried:
Clear[foo]
foo[t_] := If [ !Equal[t, ""], {t, "defined"}, {t, "undefined"} ]
DynamicModule[{symbol = ""},
Column[{
Row[{"Text field:", InputField[Dynamic[symbol], String]}],
foo[ Dynamic[symbol] ]
} ]
]
but this produces a kind of odd unevaluated If block:
I'm clearly doing something wrong with how I'm testing or using the input variable or form, but it's not obvious to me what that is?
Dynamic@foo[symbol]
,Dynamic
gives head. TryStringQ[Dynamic["test"]]
$\endgroup$Dynamic
, the code will do what is expected when usingDynamic[foo[symbol]]
instead offoo[Dynamic[symbol]]
and that isn't explained in the linked duplicate question IMO. The best answer I could find seems to be John Fultz's to this question, which I think would be a better duplicate link, but probably someone knows a good candidate on ME... $\endgroup$