Module: SimpleForm::Tailwind::OverwriteClassWithErrorOrValidClass

Included in:
Inputs::AppendStringInput, Inputs::PasswordInput, Inputs::PrependStringInput, Inputs::StringInput
Defined in:
lib/simple_form/tailwind/overwrite_class_with_error_or_valid_class.rb

Overview

This module can be mixed in to inputs to change the default :error_class and :valid_class option behavior to overwrite the existing :class value when there’s an error or the model is valid, instead of adding these classes to the :class value.

Instance Method Summary collapse

Instance Method Details

#set_input_classes(wrapper_options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_form/tailwind/overwrite_class_with_error_or_valid_class.rb', line 8

def set_input_classes(wrapper_options)
  wrapper_options = wrapper_options.dup
  error_class     = wrapper_options.delete(:error_class)
  valid_class     = wrapper_options.delete(:valid_class)

  if error_class.present? && has_errors?
    wrapper_options[:class] = error_class
  end

  if valid_class.present? && valid?
    wrapper_options[:class] = valid_class
  end

  wrapper_options
end