Class: Kadmin::Select2
- Inherits:
-
Object
- Object
- Kadmin::Select2
- Includes:
- Presentable
- Defined in:
- app/components/kadmin/select2.rb
Constant Summary collapse
- CSS_CLASS_MARKER =
'kadmin-select2'- DATA_ATTRIBUTES =
i[placeholder data_url filter_param display_property value_property page_size minimum_input_length].freeze
Instance Attribute Summary collapse
-
#data_url ⇒ String
readonly
NOTE: using this assumes the backend URL uses a Finder object.
-
#display_property ⇒ String
readonly
The name of the display property for the model (if doing remote fetching).
-
#filter_param ⇒ String
readonly
The name of the filter param when doing remote fetching.
-
#minimum_input_length ⇒ Integer
readonly
The minimum input length before trying to fetch remote data.
-
#page_size ⇒ Integer
readonly
The page size value to fetch on each select2 remote fetch.
-
#placeholder ⇒ String
readonly
Will be used as a placeholder if given.
-
#value_property ⇒ String
readonly
The name of the property used as the selected value.
Class Method Summary collapse
- .mark_tag_as_select2!(html_options) ⇒ Object
- .prepare_form_tag_options(options = {}, html_options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Select2
constructor
A new instance of Select2.
- #to_data ⇒ Object
Methods included from Presentable
Constructor Details
#initialize(options = {}) ⇒ Select2
Returns a new instance of Select2.
33 34 35 36 |
# File 'app/components/kadmin/select2.rb', line 33 def initialize( = {}) @placeholder = [:placeholder].to_s.freeze ().freeze if .present? end |
Instance Attribute Details
#data_url ⇒ String (readonly)
NOTE: using this assumes the backend URL uses a Finder object
16 17 18 |
# File 'app/components/kadmin/select2.rb', line 16 def data_url @data_url end |
#display_property ⇒ String (readonly)
Returns the name of the display property for the model (if doing remote fetching).
22 23 24 |
# File 'app/components/kadmin/select2.rb', line 22 def display_property @display_property end |
#filter_param ⇒ String (readonly)
Returns the name of the filter param when doing remote fetching.
19 20 21 |
# File 'app/components/kadmin/select2.rb', line 19 def filter_param @filter_param end |
#minimum_input_length ⇒ Integer (readonly)
Returns the minimum input length before trying to fetch remote data.
31 32 33 |
# File 'app/components/kadmin/select2.rb', line 31 def minimum_input_length @minimum_input_length end |
#page_size ⇒ Integer (readonly)
Returns the page size value to fetch on each select2 remote fetch.
28 29 30 |
# File 'app/components/kadmin/select2.rb', line 28 def page_size @page_size end |
#placeholder ⇒ String (readonly)
Returns will be used as a placeholder if given.
11 12 13 |
# File 'app/components/kadmin/select2.rb', line 11 def placeholder @placeholder end |
#value_property ⇒ String (readonly)
Returns the name of the property used as the selected value.
25 26 27 |
# File 'app/components/kadmin/select2.rb', line 25 def value_property @value_property end |
Class Method Details
.mark_tag_as_select2!(html_options) ⇒ Object
76 77 78 79 80 |
# File 'app/components/kadmin/select2.rb', line 76 def mark_tag_as_select2!() css_classes = Array.wrap([:class]) css_classes << CSS_CLASS_MARKER [:class] = css_classes.join(' ') end |
.prepare_form_tag_options(options = {}, html_options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/components/kadmin/select2.rb', line 63 def ( = {}, = {}) = .dup = .extract!(*DATA_ATTRIBUTES) select2 = new() = { data: {}, class: '' }.merge() [:data].merge!(select2.to_data) mark_tag_as_select2!() return , end |
Instance Method Details
#to_data ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/components/kadmin/select2.rb', line 50 def to_data { 'placeholder' => placeholder, 'ajax--url' => data_url, 'kadmin--filter-param' => filter_param, 'kadmin--display-property' => display_property, 'kadmin--value-property' => value_property, 'kadmin--page-size' => page_size, 'kadmin--minimum-input-length' => minimum_input_length } end |