Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.6K Views
|
4 Replies
|
1 Total Like
View groups...
Share
Share this post:

How do I create a vertical RadioButtonBar in FormObject?

RadioButtonBar has an option Appearance->"Vertical". But I am using RadioButtonBar in a FormObject (basically to create multiple-choice questions), and in the documentation this is specified as "Control"->RadioButtonBar. But that gives the default horizontal bar. How do I specify a vertical set of radio buttons? I can't supply the Appearance option to RadioButtonBar without some button specification arguments first, but in the context of FormObject those are picked up from the other parts of the FormObject spec. Here is an example of a FormObject that gives horizontal buttons, and therefore looks ugly because of the long labels:

form3 = FormObject[<|
   "Response" -> <|
     "Interpreter" -> {"None at all." -> 1, 
       "Some stuff in high school." -> 2, 
       "I have taken one or two intro-level college classes." -> 3, 
       "I have written code for research in an Independent Study or similar." -> 4, "I have mad skillz and write my own apps." -> 5}, 
     "Control" -> RadioButtonBar|>|>]
POSTED BY: Gareth Russell
4 Replies

Gareth Russell:

I was hoping someone else would jump on this but a possible solution is from stackexchange

formz = FormObject[<|
    "Response" -> <|
      "Interpreter" -> {"None at all." -> 1, 
        "Some stuff in high school." -> 2, 
        "I have taken one or two intro-level college classes." -> 3, 
        "I have written code for research in an Independent Study or \
similar." -> 4, "I have mad skillz and write my own apps." -> 5}, 
      "Control" -> 
       Function[RadioButtonBar[##, Appearance ->  "Vertical"]]|>|>];


Button[Defer[formz], None, 
 ButtonFunction :> (FrontEndExecute[{FrontEnd`SelectionCreateCell[
       FrontEnd`InputNotebook[], All], 
      FrontEnd`NotebookApply[FrontEnd`InputNotebook[], #, All], 
      FrontEnd`SelectionEvaluateCreateCell[
       FrontEnd`InputNotebook[]]}] &)]

enter image description here

This example does not have the Databins part hooked up. But it may be a start.

Update:

You want to use or try the answer from stackexchange:

Button[Defer[formz], 
 FrontEndExecute[{FrontEnd`SelectionMove[FrontEnd`EvaluationCell[], 
     After, Cell], 
    FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], #, All], 
    FrontEnd`SelectionEvaluateCreateCell[
     FrontEnd`InputNotebook[]]}] &, Evaluator -> None]
POSTED BY: Hans Michel
POSTED BY: Gareth Russell

Thanks so much! I had indeed tried it as a function, but it was the ## (SlotSequence) that I was missing: I only used a single #.

POSTED BY: Gareth Russell

Gareth Russell:

Please try the following:

FormObject[<|
  "Response" -> <|
    "Interpreter" -> {"None at all." -> 1, 
      "Some stuff in high school." -> 2, 
      "I have taken one or two intro-level college classes." -> 3, 
      "I have written code for research in an Independent Study or \
similar." -> 4, "I have mad skillz and write my own apps." -> 5}, 
    "Control" -> 
     Function[RadioButtonBar[##, Appearance ->  "Vertical"]]|>|>]

enter image description here

"Control" takes a pure Function.

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