Sha256: 099f607365f7f4ca5e125f14067244b0913677d98489bf5db550df4f533816a0

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module TaoForm
  module Components
    module Select
      class ResultComponent < TaoForm::Components::FieldComponent

        attr_reader :choices, :field_options, :placeholder

        def initialize view, builder, attribute_name, choices = nil, options = {}
          super view, builder, attribute_name, options
          @choices = choices
          @placeholder = options.delete(:placeholder)

          init_field_options
        end

        def render &block
          if block_given?
            super
          elsif builder && attribute_name
            super {
              builder.select attribute_name, choices, field_options, {disabled: options[:disabled]}
            }
          end
        end

        def self.component_name
          :select_result
        end

        private

        def init_field_options
          @field_options = {
            disabled: options.delete(:option_disabled),
            include_blank: options.delete(:include_blank),
            prompt: options.delete(:prompt)
          }
        end

        def default_options
          {class: 'select-result'}
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tao_form-0.1.9 lib/tao_form/components/select/result_component.rb
tao_form-0.1.8 lib/tao_form/components/select/result_component.rb
tao_form-0.1.7 lib/tao_form/components/select/result_component.rb
tao_form-0.1.6 lib/tao_form/components/select/result_component.rb
tao_form-0.1.5 lib/tao_form/components/select/result_component.rb
tao_form-0.1.4 lib/tao_form/components/select/result_component.rb