Sha256: 65baa18975a3cb8b3723920cac1fa8db24932f019844fd11fc7a6b88b0265a7d

Contents?: true

Size: 790 Bytes

Versions: 1

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

class FoxTail::InputBaseComponent < FoxTail::BaseComponent
  include FoxTail::Concerns::Formable
  include FoxTail::Concerns::Placeholderable

  has_option :size, default: :base
  has_option :state

  def initialize(*)
    super

    update_state_from_object!
  end

  def before_render
    super

    add_default_name_and_id
  end

  protected

  def can_read_only?
    true
  end

  def can_disable?
    true
  end

  def update_state_from_object!
    return unless object? && !options.key(:state)

    options[:state] = if object_errors?
                        :invalid
                      elsif html_attributes[:value].present?
                        :valid
                      else
                        :none
                      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fox_tail-0.1.0 app/components/fox_tail/input_base_component.rb