Sha256: 70f926ad2ff0b4b1335b9609cdaed94234bf31b40aa9ece11d4650cec5c177f0

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

module Formstrap
  class CheckboxView < ViewModel
    include Formstrap::Hintable
    include Formstrap::Labelable
    include Formstrap::Validatable
    include Formstrap::Wrappable

    def checked_value
      @checked_value || "1"
    end

    def unchecked_value
      @unchecked_value || "0"
    end

    def input_options
      keys = attributes - %i[attribute form label validate wrapper checked_value unchecked_value]
      options = to_h.slice(*keys)
      default_input_options.deep_merge(options)
    end

    def label_options
      {
        class: ["form-check-label"],
        attribute: attribute,
        form: form,
        required: required,
        text: label
      }
    end

    def wrapper_options
      default_wrapper_options.deep_merge(
        {
          class: %w[form-check mb-3]
        }
      ).deep_merge(@wrapper || {})
    end

    private

    def default_input_options
      {
        aria: {describedby: validation_id},
        class: ["form-check-input", validation_class],
        placeholder: placeholder
      }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
formstrap-0.4.5 app/models/formstrap/checkbox_view.rb
formstrap-0.4.4 app/models/formstrap/checkbox_view.rb
formstrap-0.4.3 app/models/formstrap/checkbox_view.rb
formstrap-0.4.2 app/models/formstrap/checkbox_view.rb
formstrap-0.3.5 app/models/formstrap/checkbox_view.rb
formstrap-0.3.4 app/models/formstrap/checkbox_view.rb
formstrap-0.3.3 app/models/formstrap/checkbox_view.rb
formstrap-0.3.2 app/models/formstrap/checkbox_view.rb
formstrap-0.3.1 app/models/formstrap/checkbox_view.rb
formstrap-0.3.0 app/models/formstrap/checkbox_view.rb
formstrap-0.2.1 app/models/formstrap/checkbox_view.rb
formstrap-0.2.0 app/models/formstrap/checkbox_view.rb
formstrap-0.1.3 app/models/formstrap/checkbox_view.rb
formstrap-0.1.2 app/models/formstrap/checkbox_view.rb
formstrap-0.1.1 app/models/formstrap/checkbox_view.rb
formstrap-0.1.0 app/models/formstrap/checkbox_view.rb