Class: AutocompleteInput
- Inherits:
-
SimpleForm::Inputs::TextInput
- Object
- SimpleForm::Inputs::TextInput
- AutocompleteInput
- Defined in:
- app/inputs/autocomplete_input.rb
Instance Method Summary collapse
- #add_field_id? ⇒ Boolean
-
#input(wrapper_options = nil) ⇒ Object
enable :placeholder, :maxlength.
- #prepare_html_options ⇒ Object
Instance Method Details
#add_field_id? ⇒ Boolean
72 73 74 |
# File 'app/inputs/autocomplete_input.rb', line 72 def add_field_id? ![:source_array] && ([:field_id].nil? || [:field_id]) end |
#input(wrapper_options = nil) ⇒ Object
enable :placeholder, :maxlength
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/inputs/autocomplete_input.rb', line 4 def input( = nil) out = ActiveSupport::SafeBuffer.new # prepare options = (, ) # hidden field if add_field_id? hidden_name = "#{attribute_name}_id" hidden_id = "#{object_name}_#{attribute_name}_id" ["data-field-id"] ||= hidden_id = {} [:id] = hidden_id # value value_method = "#{attribute_name}_id" if .has_key?(:value) v = [:value] elsif object.respond_to?(value_method) v = object.send(value_method) end [:value] = v unless v.nil? out << @builder.hidden_field(hidden_name, ) end # [:value] = [:value_text] unless [:value_text].nil? out << @builder.text_field(attribute_name, ) out end |
#prepare_html_options ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/inputs/autocomplete_input.rb', line 39 def = {} [:class] = [[:class], [:class]].compact # ["data-provide"] ||= "typeahead" ["autocomplete"] ||= "off" # source if [:source] ["data-source"] = [:source] elsif [:source_query] ["data-source-query"] = [:source_query] elsif [:source_array] #new_options["data-source-array"] = options[:source_array].inspect.to_s # problem with quotes " ["data-source-array"] = '['+[:source_array].map{|r| ""#{r}""}.join(',')+']' end # data options ["data-items"] = [:items] || 8 ["data-min-length"] = [:minLength] || 1 ["data-afterSelect"] = [:afterSelect] || false # value [:value] = [:value] unless [:value].nil? [:value_text] = [:value_text] unless [:value_text].nil? .merge end |