IonDen / ion.checkRadio

jQuery plugin for styling checkboxes and radio-buttons
69 stars 20 forks source link

Make it compatible with Rails form builder #11

Closed climber2002 closed 9 years ago

climber2002 commented 10 years ago

Make the rendered form compatible with Rails form builder, when Rails render a checkbox:

<label id='remember-me'>
   <%= f.check_box :remember_me %>
   <%= Spree.t(:remember_me) %>
</label>

it will put a hidden input before the checkbox, like

<label id='remember-me'>
  <input name="spree_user[remember_me]" type="hidden" value="0" />
  <input id="spree_user_remember_me" name="spree_user[remember_me]" type="checkbox" value="1" />
  Remember me
</label>

So if the user didn't check the checkbox, it will send the hidden '0' to the server. The order of the hidden and checkbox inputs must be preserved. If we call

$input.appendTo($container);
$label.appendTo($container);

The hidden input will be after the checkbox, then when the server receives the params, the value will always be 0. So remove the line

$input.appendTo($container);

to preserve the order of these two inputs.

IonDen commented 9 years ago

Should be ok in 2.0.0