Sha256: 815d730a85777d4a7d1330ca62907ca597fa6bf7b3ec04bd5dd67b9a6b1a2d3c
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module Primer module Forms module Dsl # :nodoc: class CheckBoxInput < Input DEFAULT_SCHEME = :boolean SCHEMES = [DEFAULT_SCHEME, :array].freeze attr_reader :name, :label, :value, :unchecked_value, :scheme def initialize(name:, label:, value: nil, unchecked_value: nil, scheme: DEFAULT_SCHEME, **system_arguments) raise ArgumentError, "Check box scheme must be one of #{SCHEMES.join(', ')}" unless SCHEMES.include?(scheme) raise ArgumentError, "Check box needs an explicit value if scheme is array" if scheme == :array && value.nil? @name = name @label = label @value = value @unchecked_value = unchecked_value @scheme = scheme super(**system_arguments) end def to_component CheckBox.new(input: self) end def type :check_box end private def caption_template_name @caption_template_name ||= if @scheme == :array :"#{name}_#{value}" else name.to_sym end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems