Simple_form input as both text and autocomplete

2019-06-10 00:45发布

问题:

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.

回答1:

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