Formtastic bootstrap checkbox label - ruby-on-rails

I've got phone_numbers which have 3 permissions of local, regional and national - each a boolean.
My form at the moment looks like this:
=semantic_form_for #phone_number, :html => {:class => "form-horizontal"} do |f|
=f.semantic_errors
=f.inputs do
=f.input :phone_number_type, :as => :select, :collection => PhoneNumber::PHONE_NUMBER_TYPES, :include_blank => false, :label => "Type", :required => false
=f.input :phone_number, :required => false
=f.semantic_fields_for :permission do |permission_fields|
=permission_fields.input :local, :label => false
=permission_fields.input :regional, :label => false
=permission_fields.input :national, :label => false
=f.actions do
=f.action :submit, :label => "Save"
Putting label false give each checkbox a single label to the right. Without it each checkbox has 2 labels - one on the left and one on the right. I've floated the 3 checkboxes, so they are in a horizonal line, so I'd really like local to have a label that says "Permissions" on the left and "local" on the right.
Is there a way to do this?

I just ended up hiding them with css

Related

make simple form radio buttons hidden

How can I get a hidden radio button using simple-form?
I know that simple-form has a :as => :hidden to hide a form field, and a :as => :radio_buttons to display a radio button option... but I can't have two as options on a field... :)
How can I go about this?
What I've tried:
= form.input :type,
:as => :radio_buttons,
:hidden => true,
:checked => ...
= form.input :type,
:as => [:radio_buttons, :hidden]
:checked => ...
= form.input :type,
:as => :radio_buttons,
:as => :hidden,
:checked => ...
"hidden" is a different form of input altogether - it's the same as hidden_field. If you just want to hide a radio from the user (maybe you want to show it again later) you can use "display: none" in the html for the wrapper.
= form.input :type
as: radio_buttons
wrapper_html: { style: "display: none" }
If the input should never be displayed to the user then I'd just leave it out of the page altogether. You're never going to be able to selected it after all.

Simple_form input as both text and autocomplete

I am using gem 'simple_form', '2.0' and gem 'rails3-jquery-autocomplete', '1.0.10'.
I am unable to make a string field accept two ':as' arguments.
<%= f.input :product_description , :url => autocomplete_product_name_products_path,
:as => :text, :as => :autocomplete, :placeholder=>"Type product name",
:input_html => {:class =>"span2", :rows => 6}, wrapper: :inline_label, label:false %>
If I remove :as => :text, the auto-complete part works but ':rows => 6' part fail.
And if I keep both, I get 6 rows but the auto-complete stops working.
I need this field to have have multiple rows as well as auto-complete.
This is a really silly question but I am stuck. Please help.
Simple Form doesn't define an autocomplete input. But if you need an autocomplete input and the text type I think you can do:
f.input :product_description ,
:url => autocomplete_product_name_products_path,
:as => :autocomplete,
:placeholder=>"Type product name",
:input_html => {:class =>"span2", :rows => 6, type => :text },
wrapper: :inline_label, label: false

remove a blank option of select field that was generated by SimpleForm

I have this piece of code:
= f.input :category, :as => :select, :label => false, :collection => Choices["Categories"]
Choices["Categories"] is just a hash of key=>value pairs.
SimpleForm generates a select field with all needed options, but it also makes the first option blank. This blank option is present in all select fields that were generated by SimpleForm.
But I don't want to have a blank option. Is there a way to get rid of it?
Something like :allow_blank_option => false?
I tried to make a presence validation of this attribute hoping that SimpleForm will detect it, but it didn't help.
You can pass a include_blank: false, include_hidden: false option:
= f.input :category, :as => :select, :label => false, :collection => Choices["Categories"], include_blank: false, include_hidden: false
or you can customize call back action in your model to remove any empty string in the array parameter, assuming a parameter with the name "types":
before_validation :remove_empty_string
def remove_empty_string
types.reject! { |l| l.empty? }
end
To remove a blank field from select it is necessary to show the selected so add selected: 1
Then set prompt to anything like prompt: "Please Select"
The final output will be
<%= select("social_links",:option_id, Option.all.collect {|p| [ p.name, p.id ] },{ selected: 1 , prompt: "Please Select"}, { class: 'form-control' , required:true})%>

Why does my Rails FormHelper (Formtastic) not display booleans correctly?

I am using Formtastic and I have a simple boolean field. In my view, I have
<%= f.input :active, :label => "Enabled?", :as => :select, :include_blank => false, :collection => [ ["Yes", true], ["No", false] ] %><br />
It saves to the database just fine. But when it loads, it always shows the first value ("Yes").
What am I missing? It should default to "No" when the field is false.
Thanks for any tips.
EDIT
When I put the ["No", false] first, it works!
<%= f.input :active, :label => "Enabled?", :as => :select, :include_blank => false, :collection => [ ["No", false], ["Yes", true] ] %>
Why would that matter?????
Here is a submitted bug/patch on the topic
https://rails.lighthouseapp.com/projects/8994/tickets/5702-options_for_select-do-not-select-boolean-values-correctly
and it is fixed in rails >= v3.0.3
What happens if you remove the :include_blank => false? Is the first option (blank) selected? If so, could the value for the attribute be nil and not false?

Rails: Formtastic: Select-Boxes without primary blank field

It's about Rails and Formtastic.
How can I add a select box with formtastic without an initial/primary blank field? So that the initially selected item is the first item with content.
Have you tried :include_blank => false ?
According to this (line 718) http://github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb that should work.
You resolve this one of two ways:
First option: In each select box, specify if there should be a blank line or not. Options are:
<%= f.input :author, :as => :select, :include_blank => false %>
<%= f.input :author, :as => :select, :include_blank => true %>
<%= f.input :author, :as => :select, :include_blank => "No author" %>
The last version displays "No Author" as the display in the drop down, but submits the value as blank.
Second Option: Set the default in the config/initializers/formtastic.rb.
# Should select fields have a blank option/prompt by default?
# Defaults to true.
Formtastic::FormBuilder.include_blank_for_select_by_default = false
By default, this is set to true and all your drop downs will have blank options in them. Set it to false, and by default they all won't.

Resources