Message Boards Message Boards

0
|
4145 Views
|
18 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Multiple InputFields

Posted 10 years ago

Hi, I was trying to write a code so as to have output multiple dynamic input fields, however when I try to input one field it automatically puts the same value in the other fields, I need them to be input separately. Thanks!

n = 2;
For[i = 0, i <= n + 1, i++
    {Print["\[Rho][", i, "]"], 
     InputField[Dynamic[\[Rho][i]]] // Print};
    ];
POSTED BY: Al Guy
18 Replies
Posted 10 years ago

Might it be it's a conflict of multiple dynamics?

POSTED BY: Al Guy
POSTED BY: David Reiss
Posted 10 years ago
 InputField[Dynamic[#], FieldSize -> 5] &[n]

 Dynamic@If[NumberQ[n], 
   Grid@Table[{"\[Rho][" <> ToString[i] <> "]", 
      InputField[Dynamic[#], FieldSize -> 5] &[\[Rho][i]], 
      Checkbox[Dynamic[#]] &[c\[Rho][i]], 
      "\[Sigma][" <> ToString[i] <> "]", 
      InputField[Dynamic[#], FieldSize -> 5] &[\[Sigma][i]], 
      Checkbox[Dynamic[#]] &[c\[Sigma][i]]}, {i, 0, n}] ]


 Dynamic[c\[Rho][1]]

When I put them in the package with Print@ it returns an error. So How can I print this from the package or some outside source? It Doesn't work in notebook either.

POSTED BY: Al Guy
Posted 10 years ago
POSTED BY: Al Guy

Generally the idea of a package is to define functions that you will then call after the package is loaded. But in any event, what is returned when you load a package using either Needs or Get is the result of the last expression that was executed when loaded.

You can certainly use Print in your package code, but it is not advised. It is best to use an approach to architecting your code in Mathematica so as to avoid this approach. It will lead to odd behaviors since you'd be trying to make Print do things it was not designed for.

POSTED BY: David Reiss
Posted 10 years ago

Another thing is that I need to output something from the package i write, but unless I use print , it doesn't output into the notebook from where i call the package.

POSTED BY: Al Guy
Posted 10 years ago

I understand I should not use Print, but why doesn't it work here? It works without Print

POSTED BY: Al Guy
POSTED BY: David Reiss
Posted 10 years ago
POSTED BY: Al Guy

Again, I am not sure if you are encountering a bug or the way Enter is used on Windows.

However, generally you do not want to use Enter in the input fields. You just typ in content and the dynamic values are updated. To move from one input field to another you use Tab or click in the new input field. When you do either of these the dynamic values will be updated.

POSTED BY: David Reiss
Posted 10 years ago

And this happens only when I use the num keys' enter.

POSTED BY: Al Guy
Posted 10 years ago

I am on Windows 7, I restarted it, still same.

POSTED BY: Al Guy

Hmmmm.... I do not see that behavior on my system: Mathematica 10 on Mac OSX.

POSTED BY: David Reiss
Posted 10 years ago

But I just type a number and press enter, without any shift, and it still does that.

POSTED BY: Al Guy
POSTED BY: David Reiss
Posted 10 years ago

There seems to be some minor issue. When it outputs the fields and I enter number and press "Enter", it takes the whole thing as input and outputs the same fields again. How can I overcome this? Thanks.

POSTED BY: Al Guy
Posted 10 years ago

Thank you very much, I appreciate!

POSTED BY: Al Guy
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract