Sha256: 17b45db96171b26ccf146bbb15be9f022461c9d82c264404f0e89a1163b5de17

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

#*************************************************************************************
# Build complex graphical input field.
#*************************************************************************************
module Caisson::Helpers::Form::Field
  class Select < Caisson::Helpers::Form::Field::Base
    #*************************************************************************************
    # PUBLIC INSTANCE METHODS
    #*************************************************************************************
    def build(name, choices, selection, options={})
      options.reverse_merge!(class: nil, submit: false, translate: true)

      choices = get_choices(choices, options[:translate])

      return select_tag(name, options_for_select(choices, selection), generate_attributes(options))
    end

    private

    def generate_attributes(options)
      attributes = { class: ['select-field', options.delete(:class)].flatten.compact.join(' ') }
      attributes['data-submit'] = 1 if options[:submit]

      return attributes
    end

    def get_choices(choices, translate)
      case
        when translate then choices # TODO: Translate the fields
        when (not choices.is_a?(Array)) then choices.choices_for_select # choices are a list of records
        else choices
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caisson-0.0.3 lib/caisson/helpers/form/field/select.rb
caisson-0.0.2 lib/caisson/helpers/form/field/select.rb