0
$\begingroup$

If I have a bunch of input fields, I can tab between them quite conveniently, but if I want to navigate between the input fields and another element (in my case, a button), I have to click on the button manually. Is there any option or other code construct that would allow the user to tab out of an input field and takes the focus to the button? Ideally I could just press enter and the button would activate. A simple example:

Column[{
  TableForm[{ 
    Row[{
      InputField[Dynamic@var, Number, ImageSize -> 150], 
      InputField[Dynamic@unit, String, ImageSize -> 150]
    }]// Deploy
  }],
  Button["print", Print[#1] & [Quantity[var, unit]]]
}]
$\endgroup$

1 Answer 1

1
$\begingroup$

This is not an answer. It is a suggestion about how you might simplify your code. I suggest that the simpler expression

Column[{
  Row[{
    InputField[Dynamic @ var, Number, ImageSize -> 150], 
    InputField[Dynamic @ unit, String, ImageSize -> 150]
  }],
  Button["Print", Print[Quantity[var, unit]]]
}]

will work just a well as the one you have posted. More generally, I suggest never combining TableForm with Row, Column, or Grid.

$\endgroup$
3
  • $\begingroup$ Ok, thanks! Can I ask why you'd avoid TableForm? $\endgroup$
    – user15921
    Commented Jun 13, 2014 at 12:43
  • $\begingroup$ @user15921. I don't say avoid TableForm. It's fine when used alone, TableForm is very old -- goes all the back to Version 1. Row, Column, and Grid are much newer (Version 6) and much more capable. They can do everything TableForm can do and much more. This means that TableForm simply isn't necessary when you use the newer formatting functions. Further, there are situations where the old and new formatting functions don't play well together. In your code TableForm wasn't doing any harm, it simply wasn't having any effect. $\endgroup$
    – m_goldberg
    Commented Jun 13, 2014 at 13:12
  • $\begingroup$ That makes sense. Thanks for explaining! $\endgroup$
    – user15921
    Commented Jun 13, 2014 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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