Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to submit on radio button click and use images only without radio button visible #1134

Closed
campgurus opened this issue Mar 3, 2015 · 3 comments

Comments

@campgurus
Copy link

I am trying to use formtastic to create a simple voting form with one radio button question. It is working but I want to make two adjustments and I want to know if it can be done with formtastic.

First, I want the form to submit onclick of either radio button input.

Second, I want to substitute images for the buttons entirely.

Here is my current code:

<%= semantic_form_for @vote do |f| %>
<%= f.hidden_field :matchup_id, :value => @matchup.id %>
<%= f.hidden_field :user_id, :value => @user.try(:id) %>
<%= f.hidden_field :contest_id, :value => @contest.id %>
<%= f.inputs do %>
<%= f.input :chosen_id, :as => :radio, :collection => { image_tag(Item.find(@matchup.contender_id).avatar.large_avatar)=> @matchup.contender_id, image_tag(Item.find(@matchup.opponent_id).avatar.large_avatar) => @matchup.opponent_id } %>
<%= hidden_field_tag :user_id, @user.try(:id) %>
<% end %>
<%= f.actions do %>
<%= f.action :submit %>
<% end %>
<% end %>

Can you point me in the right direction?

@justinfrench
Copy link
Member

Hello. Anything with onclick is JavaScript, and you should be able to use jQuery to attach an onclick event to those radio inputs without touching the markup that Formtadtic generates. have a look at the HTML generated and the jQuery docs and have a go.

For "images instead of buttons", this is really a CSS issue. You can hide the buttons pretty easy, and if the images are in the labels, most browsers already treat the label as a click target. What I'm not 100% sure on is how to get images inside the labels.

Is the code you have working? If not, what's happening?

@campgurus
Copy link
Author

Ok. I will figure out the jquery. In the current code, the button is clicked by clicking the image, butt the little radio button circle is still visible. I am trying to get the image only. Is that addressable in css?

@justinfrench
Copy link
Member

The CSS property you want is display: none and you'd apply that to all the input elements in the right part of the form. Closing this for now, as none of this is particularly about Formtastic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants