Group Abstract Group Abstract

Message Boards Message Boards

0
|
171 Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Radio button bar in square layout

Posted 15 days ago

I'm stuck. I can arrange four radio buttons in a square layout with this code:

RadioButtonBar["A", {"A", "B", "C", "D"}, Appearance -> "Vertical" -> {2, 2}]

enter image description here

That's exactly how I want the layout. However, when I place it inside a FormObject, I get unwanted displayed code or I can't get the radio buttons to retain this square configuration:

FormObject[<|
    "CHOOSE: " -> <|
        "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4},
        "Control" -> 
     RadioButtonBar["A", {"A", "B", "C", "D"}, 
      Appearance -> "Vertical" -> {2, 2}]
      |>
  |>]

enter image description here

I did ask the Notebook Assistance Chat, but it was not helpful helpful in this case (though it usually is). It seems I've made a mistake and don't understand some nuance of FormObject that would make this work. So I appeal to you all. What am I doing wrong?

Thanks in advance,

Mark

POSTED BY: Mark Greenberg
2 Replies
Posted 13 days ago

Thank you, Michael. Both of your suggestions worked. I went with your first suggestion because I could more clearly understand the function used to define the control. I also learned from your explanation.

Thanks again,

Mark

POSTED BY: Mark Greenberg

Try this:

FormObject[<|"CHOOSE: " -> <|
    "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4},
    "Control" -> (RadioButtonBar[#, #2, Appearance -> "Vertical" -> {2, 2}] &)
    |>
  |>]

The control value should be a function with a slot (#) to accept the dynamic local variable created by FormObject and another (#2) to accept the "Interpreter" argument.

The value you see in your output, "~216d9372a6753210", is the same as I see. It is the initial value of the local variable. An odd choice. I'm not sure why, except that it is unlikely to match a valid value for any control. It is followed by the interpreter. Note the two are between brackets [...]. That means your static radio-button bar is called as if it were a function, and two arguments were passed to it. Like this:

RadioButtonBar[
  "A", {"A", "B", "C", "D"}, 
  Appearance -> "Vertical" -> {2, 2}
  ][Dynamic[var], Interpreter[{"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4}]]

In my suggestion, the call ends up being

RadioButtonBar[
  Dynamic[var], Interpreter[{"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4}] 
  Appearance -> "Vertical" -> {2, 2}
  ]

(The variable var is localized and created internally. We don't need to know exactly what it is.)

Fiddling around, I discovered this works, too:

FormObject[<|
  "CHOOSE: " -> <|
    "Interpreter" -> {"A" -> 1, "B" -> 2, "C" -> 3, "D" -> 4},
    "Control" -> (RadioButtonBar["A", {"A", "B", "C", "D"}, 
        Appearance -> "Vertical" -> {2, 2}] &)
    |>
  |>]

So it is an alternative to my first suggestion.

Caveat: I haven't used forms, and I don't know which of the two alternatives is to be preferred. Someone else will have to answer that.

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