Sha256: ab30c9b7e3272918218e76268241ee810703df7ce0e630ea4ebbfd54ebbbad51

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module LatoCore

  class Inputs::Select::Cell < Cell

    @@requested_args = [:name]

    @@default_args = {
      value: '',
      label: '',
      placeholder: '',
      help: '',
      required: false,
      options: [],
      option_value: 'value',
      option_name: 'name',
      option_blank: true,
      class: 'md-12'
    }

    def initialize(args = {})
      @args = validate_args(
        args: args,
        requested_args: @@requested_args,
        default_args: @@default_args
      )

      set_conditions
    end

    def show
      render 'show.html'
    end

    private

      def set_conditions
        @show_label = !@args[:label].nil? && !@args[:label].blank?
        @show_help = !@args[:help].nil? && !@args[:help].blank?
        @options = generate_options
      end

      def generate_options
        options = []
        @args[:options].each do |option|
          if option.is_a?(Hash)
            options.push({value: option[@args[:option_value].to_sym], name: option[@args[:option_name].to_sym]})
          else
            options.push({value: option, name: option})
          end
        end
        return options
      end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lato_core-2.1.1 app/cells/lato_core/inputs/select/cell.rb
lato_core-2.1 app/cells/lato_core/inputs/select/cell.rb