Class: AjaxFilterInput
- Inherits:
-
Formtastic::Inputs::StringInput
- Object
- Formtastic::Inputs::StringInput
- AjaxFilterInput
- Includes:
- ActiveAdmin::Inputs::Filters::Base
- Defined in:
- app/inputs/ajax_filter_input.rb
Instance Method Summary collapse
- #eq_input_name ⇒ Object
-
#get_selected_value(display_name) ⇒ Object
rubocop:disable Style/RescueModifier.
-
#input_html_options ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #to_html ⇒ Object
Instance Method Details
#eq_input_name ⇒ Object
13 14 15 |
# File 'app/inputs/ajax_filter_input.rb', line 13 def eq_input_name "#{method}_eq" end |
#get_selected_value(display_name) ⇒ Object
rubocop:disable Style/RescueModifier
32 33 34 35 36 |
# File 'app/inputs/ajax_filter_input.rb', line 32 def get_selected_value(display_name) filter_class = method.to_s.chomp("_id").classify.constantize selected_value = @object.conditions.first.values.first.value rescue nil filter_class.find(selected_value).send(display_name) if !!selected_value end |
#input_html_options ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/inputs/ajax_filter_input.rb', line 18 def opts = {} opts[:class] = ['select2-ajax'].concat([@options[:class]] || []).join(' ') opts["data-fields"] = (@options[:fields] || []).to_json opts["data-url"] = @options[:url] || "" opts["data-response_root"] = @options[:response_root] || @options[:url].to_s.split('/').last opts["data-display_name"] = @options[:display_name] || "name" opts["data-minimum_input_length"] = @options[:minimum_input_length] || 1 opts["data-width"] = @options[:width] || "100%" opts["data-selected"] = get_selected_value(opts["data-display_name"]) super.merge opts end |
#to_html ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/inputs/ajax_filter_input.rb', line 4 def to_html input_wrapping do [ label_html, builder.text_field(eq_input_name, ) ].join("\n").html_safe end end |