Sha256: f7e10d21c9a76f476b5a01d2320f330f0e9d09dc50d6c2f6d347b53ee602eeac

Contents?: true

Size: 790 Bytes

Versions: 1

Compression:

Stored size: 790 Bytes

Contents

module HungryForm
  module Rails
    # This module adds view specific methods to every HungryForm element
    module Renderable
      def wrapper_class
        classes = []
        classes << attributes[:wrapper_class] if attributes[:wrapper_class]
        classes << 'hidden' unless visible?

        invalid = self.is_a?(HungryForm::Elements::Base::ActiveElement) &&
                  error.present?

        if invalid
          classes << HungryForm.configuration.rails.error_class || 'invalid'
        end

        classes.join(' ') if classes.any?
      end

      def input_attributes
        except_attrs = [
          configuration[:input_attributes_except],
          :wrapper_class, :checked
        ]
        attributes.except(*except_attrs.flatten)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-rails-0.0.6 lib/hungryform/rails/renderable.rb