You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
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?
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.
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?
The text was updated successfully, but these errors were encountered: