Class: TaoForm::Components::SelectComponent
- Inherits:
-
FieldComponent
- Object
- TaoOnRails::Components::Base
- FieldComponent
- TaoForm::Components::SelectComponent
- Defined in:
- lib/tao_form/components/select_component.rb
Instance Attribute Summary collapse
-
#block_for_render ⇒ Object
readonly
Returns the value of attribute block_for_render.
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#max_list_size ⇒ Object
readonly
Returns the value of attribute max_list_size.
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
Attributes inherited from FieldComponent
Class Method Summary collapse
Instance Method Summary collapse
- #clearable ⇒ Object
-
#initialize(view, builder, attribute_name, choices = nil, options = {}, html_options = {}) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #placeholder ⇒ Object
- #render(&block) ⇒ Object
- #render_list ⇒ Object
- #render_result ⇒ Object
Constructor Details
#initialize(view, builder, attribute_name, choices = nil, options = {}, html_options = {}) ⇒ SelectComponent
Returns a new instance of SelectComponent.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tao_form/components/select_component.rb', line 11 def initialize view, builder, attribute_name, choices = nil, = {}, = {} super view, builder, attribute_name, @choices = choices @max_list_size = .delete(:max_list_size) @disabled = [:disabled].presence || false @multiple = .delete(:multiple) || .delete(:multiple) || false [:multiple] = @multiple [:remote] = .delete(:remote) if [:remote].present? && [:remote].is_a?(Hash) [:remote] = [:remote].to_json end = end |
Instance Attribute Details
#block_for_render ⇒ Object (readonly)
Returns the value of attribute block_for_render.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def block_for_render @block_for_render end |
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def choices @choices end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def disabled @disabled end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def end |
#max_list_size ⇒ Object (readonly)
Returns the value of attribute max_list_size.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def max_list_size @max_list_size end |
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def multiple @multiple end |
Class Method Details
.component_name ⇒ Object
66 67 68 |
# File 'lib/tao_form/components/select_component.rb', line 66 def self.component_name :select end |
Instance Method Details
#clearable ⇒ Object
50 51 52 |
# File 'lib/tao_form/components/select_component.rb', line 50 def clearable @clearable ||= [:include_blank].present? || [:prompt].present? end |
#placeholder ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tao_form/components/select_component.rb', line 54 def placeholder @placeholder ||= if [:placeholder].present? [:placeholder] elsif [:include_blank].present? && [:include_blank].is_a?(String) [:include_blank] elsif [:prompt].present? && [:prompt].is_a?(String) [:prompt] else t :placeholder end end |
#render(&block) ⇒ Object
28 29 30 31 |
# File 'lib/tao_form/components/select_component.rb', line 28 def render &block @block_for_render = block super end |
#render_list ⇒ Object
46 47 48 |
# File 'lib/tao_form/components/select_component.rb', line 46 def render_list view.tao_select_list max_list_size: max_list_size end |
#render_result ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tao_form/components/select_component.rb', line 33 def render_result if multiple view.tao_multiple_select_result( builder, attribute_name, choices, , disabled: disabled, &block_for_render ) else view.tao_select_result( builder, attribute_name, choices, , placeholder: placeholder, clearable: clearable, disabled: disabled, &block_for_render ) end end |