class Formtastic::Inputs::DatalistInput
Outputs a label and a text field, along with a datalist tag datalist tag provides a list of options which drives a simple autocomplete on the text field. This is a HTML5 feature, more info can be found at {developer.mozilla.org/en/docs/Web/HTML/Element/datalist <datalist> at MDN} This input accepts a :collection option which takes data in all the usual formats accepted by {apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select options_for_select}
@example Input is used as follows
f.input :fav_book, :as => :datalist, :collection => Book.pluck(:name)
Public Instance Methods
data_list_html()
click to toggle source
# File lib/formtastic/inputs/datalist_input.rb, line 35 def data_list_html html = builder.template.options_for_select(collection) builder.template.content_tag(:datalist,html, { :id => html_id_of_datalist }, false) end
html_id_of_datalist()
click to toggle source
# File lib/formtastic/inputs/datalist_input.rb, line 31 def html_id_of_datalist "#{@name}_datalist" end
input_html_options()
click to toggle source
Calls superclass method
Formtastic::Inputs::Base::Stringish#input_html_options
# File lib/formtastic/inputs/datalist_input.rb, line 27 def input_html_options super.merge(:list => html_id_of_datalist) end
to_html()
click to toggle source
# File lib/formtastic/inputs/datalist_input.rb, line 18 def to_html @name = input_html_options[:id].gsub(/_id$/, "") input_wrapping do label_html << builder.text_field(method, input_html_options) << # standard input data_list_html # append new datalist element end end