Sha256: ab3a95506a407b70c62bff25fd33fe445d7a05858dd9e6d6831bb53f6c3ddc27

Contents?: true

Size: 1.35 KB

Versions: 57

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require "action_view"

module Playbook
  module PbSelect
    class Select < Playbook::KitBase
      prop :blank_selection
      prop :disabled, type: Playbook::Props::Boolean, default: false
      prop :error
      prop :include_blank
      prop :label
      prop :multiple, type: Playbook::Props::Boolean, default: false
      prop :name
      prop :onchange
      prop :options, type: Playbook::Props::HashArray, required: false, default: []
      prop :required, type: Playbook::Props::Boolean, default: false

      def classname
        generate_classname("pb_select")
      end

      def select_wrapper_class
        "pb_select_kit_wrapper" + error_class
      end

      def options_to_array
        options.map { |option| [option[:value_text] || option[:value], option[:value]] }
      end

      def selected
        selections = options.map { |option| option[:value] if option[:selected] == true }.compact
        if selections.empty?
          nil
        else
          selections
        end
      end

      def disabled_options
        disabled_options = options.map { |option| option[:value] if option[:disabled] == true }.compact
        if disabled_options.empty?
          nil
        else
          disabled_options
        end
      end

    private

      def error_class
        error ? " error" : ""
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
playbook_ui-9.6.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.6.1.pre.deps1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.6.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.5.0.alpha.rs.downgrade app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.5.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.4.0.alpha.sisense app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.4.0.alpha.user.kit.bug app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.4.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.1.pre.alpha2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.4.0.pre.alpha2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.4.0.pre.alpha1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.1.pre.alpha1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0.alpha.inline3 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0.pre.alpha.password.strength.2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0.alpha.inline2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0.alpha.inline1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0.pre.alpha.password.strength.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.3.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.2.2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.2.1 app/pb_kits/playbook/pb_select/select.rb