check boxes with twitter bootstrap integration
Hi,
I'm using the latest version (e6fe814bbe5bb025e0489d3999b872bd936acd94) from git and there are some problems with check boxes:

- The hint is displayed in the same line as the check box. I guess this is not intended.
- The label is displayed on the left side of the check box. Is it possible to configure simple_form using the new syntax to display it on the right side? It looks nicer in my opinion.
- (not related to check boxes, but still) The generated scaffold form generator should use the class
form-actionsinstead ofactionsfor the buttons when using twitter bootstrap.
The integration is great!
Best regards, Fabian
Hey, thanks for your input. We're going to check your report, meanwhile we're releasing a 2.0.rc release that you can check and play with.
About the label at left, this is how Bootstrap handles checkboxes as you can see in their examples: http://twitter.github.com/bootstrap/base-css.html#forms.
Let us know about any other issue. Thanks.
Hey, I've actually checked the bootstrap documentation, and if you take a look at the 'Basic form'-example, the label is actually on the right side of the check-box. But I agree that it seems to be on the left side for horizontal forms.
Hi,
May I note that the position of the label also depends on country specific conventions. In the Netherlands the convention is to put the label on the right side of the radio/check-boxes (always).
@fschwahn I was checking this and seems you can achieve that check box style by giving :boolean_style => :nested to the f.input call. That should give you a similar check box wrapped by a label and with text inside. By default SimpleForm will stick with the label on left. Could you please give it a try? Thanks
I believe your 3rd point is ok now :)
Hey,
I just pulled the latest version from git an reran the generator so I'm up to date. But passing :boolean_style => :nested does not change the markup at all, probably because the boolean style for bootstrap is already :nested by default. Using :boolean_style => :inline also didn't help.
Just to clear things up a bit, simple_form right now generates this markup for a boolean field:
<div class="control-group boolean optional">
<label class="boolean optional" for="user_remember_me">Remember me?</label>
<div class="controls">
<input name="user[remember_me]" type="hidden" value="0">
<label class="checkbox">
<input class="boolean optional" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
</label>
</div>
</div>
The markup I'd like it to generate is something like the following:
<div class="control-group boolean optional">
<div class="controls">
<input name="user[remember_me]" type="hidden" value="0">
<label class="checkbox" for="user_remember_me">
<input class="boolean optional" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1"> Remember me?
</label>
</div>
</div>
Is it possible to configure this behavior?
Best regards, Fabian
Yes, it is possible but it'll need a different wrapper =(. Take a look at #426 for more info. We'll check how to improve that.
hmm, both issues have been closed now. So did you add the needed wrapper?
The label should have the new checkbox class.
Ah ok, just if anyone else is wondering, add the following to the config/initializers/simple_form.rb:
config.wrappers :checkbox, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :tag => 'div', :class => 'controls' do |ba|
ba.use :label_input
end
end
and then use this wrapper as follows:
<%= f.input :remember_me, :as => :boolean, :wrapper => :checkbox %>
@ fschwahn thanks for that, saved me some time
@fschwahn great, just what I needed as well!
@fschwahn And just what i needed as well! Thanks!
@fschwahn +1, great ! Thanks.
@fschwahn +1 thx
Also label of checkbox was aligned right with latest twitter bootstrap and simple_form 2 so I added this:
//Checkbox right fix label.checkbox { text-align: left !important; } input[type=checkbox] { margin-right: 10px !important; }
in scss file to override the bootstrap css and make it align more nicely :)
+1 thanks for posting!
+1 thanks @fschwahn
+1 this is great!
This is really close, but there shouldn't be a control-label class on the checkbox label or it behaves as though it is in the label column in horizontal forms (and this really starts to matter if you're using the responsive styles).
You can use :label => false, :inline_label => true on the checkbox. Or specify that to be the default in app/inputs/boolean_input.rb:
class BooleanInput < SimpleForm::Inputs::BooleanInput
def initialize(builder, attribute_name, column, input_type, options = {})
super(builder, attribute_name, column, input_type, {:label => false, :inline_label => true}.merge(options))
end
end