How to add radio buttons, checkboxes?

24 views
Skip to first unread message

Vishi

unread,
Oct 30, 2014, 12:38:24 PM10/30/14
to ged...@googlegroups.com
HI
Could someone help me with adding radiobuttons/checkboxes. I believe it would require custom helpers, but I cant understand how to add it. Could someone help please?
Thanks

Matthew Eernisse

unread,
Oct 31, 2014, 4:56:03 PM10/31/14
to ged...@googlegroups.com
You need to use the `contentTag` helper:

http://geddyjs.org/reference#helpers_content_tag

The 'type' attribute will default to 'text', but you can use 'radio' or 'checkbox'.

Vishi

unread,
Nov 3, 2014, 8:01:10 AM11/3/14
to ged...@googlegroups.com
Hi Matthew
Thanks for your post, I am able to create radiobuttons/checkboxes in the views. However the data does not get captured in the datastore.

    <%- contentTag('input', thing.description, {type:'radio', class:'span6', name:'radio1', id:'option1', value:'option1'}) %>
    <%- contentTag('input', thing.description, {type:'radio', class:'span6', name:'radio1', id:'option2', value:'option2'}) %>

In the _datastore.json there is no description even though i select one of the radio buttons. I would have expected to see "description": "option1" in the datastore. Could you help me get this working please?
{"createdAt":"2014-11-03T12:54:22.011Z","title":"asd","date":"2014-11-12T00:00:00.000Z","id":"E302A23A-225F-46C5-B28F-5FD127812482","type":"Thing"}

Regards
-Vishi

Vishi

unread,
Nov 3, 2014, 7:05:09 PM11/3/14
to ged...@googlegroups.com
Hi,
Note that the server log shows the POST request capturing the radio button correctly. But for some reason it does not make it way to the datastore. Any clue, anyone ?

 { method: 'POST',   controller: 'Things',   action: 'create',   title: 'asd',   radio1: 'option2',   date: '12/10/14' }

Vishi

unread,
Nov 3, 2014, 7:46:17 PM11/3/14
to ged...@googlegroups.com
I got the answer with ton of help on irc

I need to match the name property of the radio buttons with the model property name. So this works

    <%- contentTag('input', thing.description, {type:'radio', class:'span6', name:'description', id:'option1', value:'option1'}) %>
    <%- contentTag('input', thing.description, {type:'radio', class:'span6', name:'description', id:'option2', value:'option2'}) %>


Thanks everyone
Reply all
Reply to author
Forward
0 new messages