Sha256: 3a3697f146206765d2d515abc34dd1b9448c32fe7500072ba0aa4213ef2633b7

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

#*************************************************************************************
# TOCOMMENT
#*************************************************************************************
module Caisson::Helpers::Form::Builder::Field
  class Select < Caisson::Helpers::Form::Builder::Field::Base
    #*************************************************************************************
    # PUBLIC INSTANCE METHODS
    #*************************************************************************************
    def build
      @options.reverse_merge!(choices: nil, include_blank: false)

      choices = parse_choices @options[:choices]

      @options.delete(:choices)
      @options.delete(:include_blank)
      @options[:translate] = false

      Caisson::Helpers::Form::Field::Select.new(@core).build(field_name, choices, value, @options)
    end

    private

    #*************************************************************************************
    # PRIVATE INSTANCE METHODS
    #*************************************************************************************
    def parse_choices(choices)
      if choices
        if not choices.is_a? Array or not choices.first.is_a? Array
          # choices are a list of records
          choices = choices.choices_for_select
          choices.insert(0, interpreti.blank_choice(name)) if @options[:include_blank]
        end
      else
        choices = interpreti.field_choices(name, include_blank: @options[:include_blank])
      end

      return choices
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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