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.
7 8 9 10 11 12 13 14 15 |
# File 'lib/tao_form/components/select_component.rb', line 7 def initialize view, builder = nil, attribute_name = nil, choices = nil, = {} super view, builder, attribute_name, @choices = choices @multiple = @options[:multiple].presence || false end |
Instance Attribute Details
#block_for_render ⇒ Object (readonly)
Returns the value of attribute block_for_render.
5 6 7 |
# File 'lib/tao_form/components/select_component.rb', line 5 def block_for_render @block_for_render end |
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
5 6 7 |
# File 'lib/tao_form/components/select_component.rb', line 5 def choices @choices end |
#list_options ⇒ Object (readonly)
Returns the value of attribute list_options.
5 6 7 |
# File 'lib/tao_form/components/select_component.rb', line 5 def @list_options end |
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
5 6 7 |
# File 'lib/tao_form/components/select_component.rb', line 5 def multiple @multiple end |
#result_options ⇒ Object (readonly)
Returns the value of attribute result_options.
5 6 7 |
# File 'lib/tao_form/components/select_component.rb', line 5 def @result_options end |
Class Method Details
.component_name ⇒ Object
54 55 56 |
# File 'lib/tao_form/components/select_component.rb', line 54 def self.component_name :select end |
Instance Method Details
#clearable ⇒ Object
38 39 40 |
# File 'lib/tao_form/components/select_component.rb', line 38 def clearable @clearable ||= .delete(:clearable) || [:include_blank].present? || [:prompt].present? end |
#placeholder ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tao_form/components/select_component.rb', line 42 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
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tao_form/components/select_component.rb', line 17 def render &block @block_for_render = block if view.request.variant.mobile? super else view.content_tag tag_name, do view.concat render_result view.concat render_list end end end |
#render_list ⇒ Object
34 35 36 |
# File 'lib/tao_form/components/select_component.rb', line 34 def render_list view.tao_select_list end |
#render_result ⇒ Object
29 30 31 32 |
# File 'lib/tao_form/components/select_component.rb', line 29 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 |