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.
-
#list_options ⇒ Object
readonly
Returns the value of attribute list_options.
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#result_options ⇒ Object
readonly
Returns the value of attribute result_options.
Attributes inherited from FieldComponent
Class Method Summary collapse
Instance Method Summary collapse
- #clearable ⇒ Object
-
#initialize(view, builder = nil, attribute_name = nil, choices = nil, options = {}) ⇒ SelectComponent
constructor
A new instance of SelectComponent.
- #placeholder ⇒ Object
- #render(&block) ⇒ Object
- #render_list ⇒ Object
- #render_result ⇒ Object
Constructor Details
#initialize(view, builder = nil, attribute_name = nil, choices = nil, options = {}) ⇒ SelectComponent
Returns a new instance of SelectComponent.
11 12 13 14 15 16 17 18 19 |
# File 'lib/tao_form/components/select_component.rb', line 11 def initialize view, builder = nil, attribute_name = nil, choices = nil, = {} super view, builder, attribute_name, @choices = choices @multiple = [:multiple].presence || false 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 |
#list_options ⇒ Object (readonly)
Returns the value of attribute list_options.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def 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 |
#result_options ⇒ Object (readonly)
Returns the value of attribute result_options.
9 10 11 |
# File 'lib/tao_form/components/select_component.rb', line 9 def end |
Class Method Details
.component_name ⇒ Object
51 52 53 |
# File 'lib/tao_form/components/select_component.rb', line 51 def self.component_name :select end |
Instance Method Details
#clearable ⇒ Object
35 36 37 |
# File 'lib/tao_form/components/select_component.rb', line 35 def clearable @clearable ||= .delete(:clearable) || [:include_blank].present? || [:prompt].present? end |
#placeholder ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tao_form/components/select_component.rb', line 39 def placeholder @placeholder ||= if (text = .delete(:placeholder)) text 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
21 22 23 24 |
# File 'lib/tao_form/components/select_component.rb', line 21 def render &block @block_for_render = block super end |
#render_list ⇒ Object
31 32 33 |
# File 'lib/tao_form/components/select_component.rb', line 31 def render_list view.tao_select_list end |
#render_result ⇒ Object
26 27 28 29 |
# File 'lib/tao_form/components/select_component.rb', line 26 def render_result result_method = multiple ? :tao_multiple_select_result : :tao_select_result view.send(result_method, builder, attribute_name, choices, , &block_for_render) end |