Sha256: ac0eb85dbd3062d8d2e29058dc1c717c4549fa6b8bf538169977a4a91591c662
Contents?: true
Size: 1.28 KB
Versions: 147
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Primer module Forms module Dsl # :nodoc: class MultiInput < Input include InputMethods attr_reader :name, :label def initialize(name:, label:, **system_arguments) @name = name @label = label super(**system_arguments) yield(self) if block_given? end def to_component Multi.new(input: self) end def type :multi end private def add_input(input) super check_one_input_visible! end def decorate_options(name:, **options) new_options = { name: @name, label: nil, form_control: false, **options } new_options[:data] ||= {} new_options[:data][:name] = name new_options[:data][:targets] = "primer-multi-input.fields" new_options[:id] = nil if options[:hidden] new_options[:disabled] = true if options[:hidden] # disable to avoid submitting to server new_options end def check_one_input_visible! return if inputs.count { |input| !input.hidden? } <= 1 raise ArgumentError, "Only one input can be visible at a time in a `multi' block." end end end end end
Version data entries
147 entries across 147 versions & 2 rubygems