Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Make it compatible with Rails form builder #11

Closed
wants to merge 2 commits into from

Conversation

climber2002
Copy link

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.

…__hidden container. This is to make it compatible with Rails form, as the Rails form will append a hidden input field when render f.checkbox input
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
Copy link
Owner

IonDen commented Jun 5, 2015

Should be ok in 2.0.0

@IonDen IonDen closed this Jun 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants