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
70 71 72 |
# File 'app/inputs/autocomplete_input.rb', line 70 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 |
# 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 [:input_html] ||= {} # value value_method = "#{attribute_name}_id" if object.respond_to?(value_method) v = object.send(value_method) elsif .has_key?(:value) v = [:value] end [:value] = v unless v.nil? out << @builder.hidden_field(hidden_name, ) end # out << @builder.text_field(attribute_name, ) out end |
#prepare_html_options ⇒ Object
38 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 |
# File 'app/inputs/autocomplete_input.rb', line 38 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_text] || '' .merge end |