Simple_form input as both text and autocomplete - ruby-on-rails

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

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.

Checkboxes in formtastic bootstrap

Recently, I installed the formtastic-bootstrap gem on my ruby-on-rails application. I have the following code on one of my forms that includes check-boxes:
<% if #gallery.tag_list.empty? %>
<%= f.input :tag_list, :as => :check_boxes, :label => _('Select Applicable Tags'), :collection => Gallery::DEFAULT_TAGS.sort, :wrapper_html => {:class => 'horizontal_list'} %>
<% else %>
<%= f.input :tag_list, :as => :check_boxes, :label => _('Current Tags'), :collection => #gallery.tag_list.sort, :wrapper_html => {:class => 'horizontal_list'} %>
<% end -%>
Even though formtastic-bootstrap is rendering the rest of my form correctly, my checkboxes are not showing up. The text next to the check-boxes appears, but the checkboxed themselves do not. Any suggestions to get this working are welcome. I have been trying to circumvent this little, annoying issue all day.
I had to create a bootstrapcustom.css.scss to over-ride the bootstrap properties of padding and margins on check-box elements in order to make them appear in the end.

Rails jquery datepicker date pre-loaded

I'm using jquery datepciker in a Rails app.
I would like to have the date already filled in when the form page loads. So, that the user can leave the date as-is or change it.
I was hoping the datepicker options would let me do that.
I tried this:
$("#comment_status_date").datepicker({
dateFormat: 'yy-mm-dd',
setDate: Date.now
});
But, the date field was empty.
Do I have to do some ruby code in the model or controller?
Does datepicker have an option to do this?
Thanks!!
I figured out a way:
<%= f.input :status_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => { :value => Date.today.to_s } %>
I figured out a way:
<%= f.input :status_date, :as => :string, :label => 'Date', :class => 'calendar hasDatepicker', :input_html => { :value => Date.today.to_s } %>

Formtastic bootstrap checkbox label

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

How to pre select a state in Rails Carmen state_select

What are the options I can pass in a state_select. I am trying to do :selected => state and its not working.
<%= f.state_select :state, 'US', {:prompt => '--Select One--', :selected => state}, :tabindex => autotab, :id => 'state_select, :state => state'%>
I don't think you can use state_select to do it. You'll have to use select with the state_options_for_select function in order to enter your selected state:
<%= f.select :state, state_options_for_select(state_to_select, country_code) %>
That should get you there.

Resources