Class: Formtastic::Inputs::AjaxSelect2Input
- Inherits:
-
StringInput
- Object
- StringInput
- Formtastic::Inputs::AjaxSelect2Input
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/formtastic/inputs/ajax_select2_input.rb
Instance Method Summary collapse
- #extra_input_html_options ⇒ Object
- #input_html_options ⇒ Object
- #input_html_options_name ⇒ Object
- #multiple? ⇒ Boolean
- #multiple_by_association? ⇒ Boolean
- #multiple_by_options? ⇒ Boolean
- #value ⇒ Object
Instance Method Details
#extra_input_html_options ⇒ Object
28 29 30 31 32 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 28 def { name: } end |
#input_html_options ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 4 def url_params = {} url_params[:class_name] = [:search_class] if [:search_class].present? url_params[:search_method] = [:search_method] if [:search_method].present? url_params[:default_class_name] = [:default_class_name] if [:default_class_name].present? url_params[:default_text_column] = [:default_text_column] if [:default_text_column].present? url_params[:default_id_column] = [:default_id_column] if [:default_id_column].present? url_params[:select2_options] = [:select2_options] if [:select2_options].present? href = template.select2_autocompletes_path(url_params) = { value: value }.merge().merge(super) [:data] = [:data].to_h.merge({ s2_href: href, s2_options: url_params[:select2_options].to_h.merge(multiple: multiple?) }) css_classes = [[:class], 'auto-ajax-select2', 'input-hol'] if multiple? css_classes << 'multiple' end [:class] = css_classes.compact.join(' ') end |
#input_html_options_name ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 43 def if builder..key?(:index) "#{object_name}[#{builder.options[:index]}][#{association_primary_key}]" else "#{object_name}[#{association_primary_key}]" end end |
#multiple? ⇒ Boolean
34 35 36 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 34 def multiple? || multiple_by_association? end |
#multiple_by_association? ⇒ Boolean
51 52 53 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 51 def multiple_by_association? reflection && [ :has_many, :has_and_belongs_to_many ].include?(reflection.macro) end |
#multiple_by_options? ⇒ Boolean
55 56 57 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 55 def [:multiple] || ([:input_html] && [:input_html][:multiple]) end |
#value ⇒ Object
38 39 40 41 |
# File 'lib/formtastic/inputs/ajax_select2_input.rb', line 38 def value val = object.send(association_primary_key) val.is_a?(Array) ? val.join(',') : val end |