1
$\begingroup$

Dynamic has been really useful for me but it is as well not easy to understand also. I am doing a calculation where I want some of the input fields enabled or disabled depending on where I am in the computation.

Row[{Style[" Report the result ", 13, Blue, Editable -> False], 
Checkbox[Dynamic[dod], {False, True}, Enabled -> Dynamic@Switch[sd,
   1, False,
   0, False,
   4, True,
   3, True,
   2, True]] Style[" with ", 13, Blue, Editable -> False], 
   InputField[Dynamic[NoPd], Number, FieldSize -> {12, 1.5}, 
   Enabled -> Dynamic[dod]]}]

Here sd is switching during the computation to false which makes the checkbox disabled. But the corresponding input field only depends on "dod". That means the field is enabled during the computation if the checkbox was checked before the calculation started. I would like to be able to disable the input field during the computation. I am trying to find a way to do something like

InputField[Dynamic[NoPd], Number, FieldSize -> {12, 
1.5},Enabled->If[MatchQ[{Dynamic[dod], Dynamic@Switch[sd,
   1, False,
   0, False,
   4, True,
   3, True,
   2, True]}, False], False]]

For the InputField. I know that {Dynamic[dod], Dynamic[sd]} is not a list. I can't really take Dynamic[dod] as a variable. My question somewhat similar to How can I use parts of lists with Dynamic?

but I couldn't adapt the solution of that question to mine. Please let me know if my question is not clear enough.

Any ideas? Thank you

$\endgroup$
  • 1
    $\begingroup$ Does this give what you need: Row[{Style[" Report the result ", 13, Blue, Editable -> False], Checkbox[Dynamic[dod], {False, True}, Enabled -> Dynamic[cbenabled = Switch[sd, 1, False, 0, False, 4, True, 3, True, 2, True]]] Style[" with ", 13, Blue, Editable -> False], InputField[Dynamic[NoPd], Number, FieldSize -> {12, 1.5}, Enabled -> Dynamic[dod && cbenabled]]}]? $\endgroup$ – kglr Oct 17 '18 at 18:19
  • $\begingroup$ @kglr Exactly, thank you. $\endgroup$ – Erdem Oct 18 '18 at 10:10
2
$\begingroup$
Row[{Style[" Report the result ", 13, Blue, Editable -> False], 
   Checkbox[Dynamic[dod], {False, True}, 
      Enabled -> Dynamic[cbenabled = Switch[sd, 1, False, 0, False,
         4, True, 3, True, 2, True]]] Style[" with ", 13, Blue, 
            Editable -> False], InputField[Dynamic[NoPd], Number, FieldSize -> {12, 1.5}, 
              Enabled -> Dynamic[dod && cbenabled]]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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