Message Boards Message Boards

0
|
5494 Views
|
4 Replies
|
1 Total Likes
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:

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

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

I have a follow-up question. I want a notebook with multiple such 'question' forms in it. Students will have the notebook live in class, and the forms are not for a formal quiz, but for instructor feedback — some of you will know about 'iClicker' and other such tools for this. So, I set up one Databin for the notebook, and each form sends its responses to the Databin with a different key so they appear in different 'columns' when it's read back in as a Dataset. Then they can be displayed, graphed, etc as appropriate. Here is an example of setup code that is autoevaluated at the beginning of the notebook, identifying the Databin and defining three forms that send data to it:

(* Initialize clean databin to hold class responses (INSTRUCTOR \
NOTEBOOK ONLY) *)
(* dataBins=Databins[];
If[Length[Select[dataBins,#["Name"]==="popBin1"&]]>0,DeleteObject[\
Select[dataBins,#["Name"]==="popBin1"&]]];
popBin1=CreateDatabin[<|"Name"\[Rule]"popBin1"|>]; *)

(* Locate the databin for this notebook (STUDENT NOTEBOOKS) *)

popBin1 = Select[Databins[], #["Name"] === "popBin1" &][[1]];

(* Initialize forms for responses *)

form1 = FormFunction[<|
    "Response" -> 
     "String"|>, (DatabinAdd[popBin1, <|"Q1" -> #Response|>]; 
     Print["Thanks!"]) &, 
   AppearanceRules -> <|"Title" -> "Class Response 1", 
     "Description" -> 
      "Write a short interpretation of the results in the graph", 
     "ItemLayout" -> "Vertical"|>];

form2 = FormFunction[<|"Response" -> "String"|>, 
   DatabinAdd[popBin1, <|"Q2" -> #Response|>] &, 
   AppearanceRules -> <|"Title" -> "Class Response 2", 
     "Description" -> 
      "Write a short interpretation of the results in this other \
graph", "ItemLayout" -> "Vertical"|>];

form3 = FormFunction[
   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[##, Appearance -> "Vertical"] &)|>|>,
     AppearanceRules -> <|"Title" -> "Your Coding Experince", 
      "Description" -> 
       "Choose the answer that is closest to your experience level", 
      "ItemLayout" -> "Vertical"|>], 
   DatabinAdd[popBin1, <|"Q3" -> #Response|>] &];

All the functionality works great — that is not my problem. My problem is with how the forms deploy in the notebook, if I don't want students to have to Shift-Enter in a cell with form1[]; in it. I can't use auto-evaluating cells because each form interrupts evaluation until it is submitted or canceled. So I tried Button["Question 1",form1[]] but this displays nothing; it just changes to the 'pressed' appearance for the default timeout of 5 secs and then returns to 'unpressed.' No form appears. Any thoughts about how to make a form appear when a button is pressed?

POSTED BY: Gareth Russell

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
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