Arc Forumnew | comments | leaders | submitlogin
How do you make radiobuttons?
1 point by lark 4907 days ago | 3 comments
I can't tell how this is done in Arc.


3 points by thaddeus 4907 days ago | link

Radio buttons need the 'checked' attribute to set the initial selection.

See: http://www.w3schools.com/tags/att_input_checked.asp

Mulitple radio buttons having the same name will act as a group.

See: http://www.w3schools.com/jsref/dom_obj_radio.asp

In arc, the requested attribute will reflect the currently selected radio button for the group.

Also, note that arc's gentag doesn't handle the 'checked' attribute. So you you'll need to add:

  (attribute input      checked        opstring)
into html.arc. Just put it in with the others.

Then change your code:

  (def radio (n v (o c nil))
    (gentag input type 'radio name n value v checked c))
Results:

  arc> (radio "rdgp" 1)
  <input type=radio name="rdgp" value="1">

  arc> (radio "rdgp" 2 "checked")
  <input type=radio name="rdgp" value="2" checked="checked">
Optionally, instead of extending attributes one at a time, you can write a more generic gentag macro to handle anything you throw at it. And I'm pretty sure if you did a Google search on the arc forum you might even find it's already done.

-----

1 point by lark 4907 days ago | link

I think the following does it:

  (def radio (n v)
      (gentag input type 'radio name n value v))
Though I'm not sure how to set an initial selection. Or how to retrieve the value of the selected radio button.

-----

1 point by lark 4907 days ago | link

Anyone?

-----