Method: Engine2::TypeInfo#list_select

Defined in:
lib/engine2/type_info.rb

#list_select(name, options) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/engine2/type_info.rb', line 321

def list_select name, options
    modify_field name do |info|
        info[:type] = :list_select
        values = options[:values]

        if options[:multiselect]
            info[:multiselect] = true
            case info[:otype]
            when :string
                info[:separator] = options[:separator] || ';'
                info[:validations].delete(:string_length)
            when :integer
                info[:validations].delete(:integer)
            end
            info[:max_length] = options[:max_length] || 3
            info[:max_length_html] = options[:max_length_html] || LOCS[:list_select_selected]
        end

        raise E2Error.new("type '#{values.class}' not supported for list_select modifier for field #{name}") unless values.is_a?(Hash)
        info[:values] = values.to_a
        info[:validations][:list_select] = true
    end
end