Sha256: 698b8f95305f43ee78b5d426fcf9ed0b4674041e856de2702604777a0b1dc98d

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

class BeyondFormBuilder < ActionView::Helpers::FormBuilder
  def field_wrapper(attribute, args, &block)
    label = args[:label].present? ? args[:label] : attribute.to_s.humanize

    if self.object.respond_to?(:errors) && self.object.errors.include?(attribute)
      errors = self.object.errors[attribute].join(", ")
    end

    @template.content_tag(:div, class: 'form__row') do
      @template.content_tag(:label, label, class: 'input__label') +
      @template.content_tag(:div, class: 'relative') do
        block.call +

        (@template.content_tag(:label, errors, class: "input__errors") unless errors.blank?)
      end +
      (@template.content_tag(:div, args[:hint].html_safe, class: 'input__hint') if args[:hint].present?)
    end
  end

  def email_field(attribute, args = {})
    field_wrapper(attribute, args) do
      super(attribute, args)
    end
  end

  def text_field(attribute, args = {})
    field_wrapper(attribute, args) do
      super(attribute, args)
    end
  end

  def password_field(attribute, args = {})
    field_wrapper(attribute, args) do
      super(attribute, args)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
beyond_canvas-0.3.0.pre app/form_builders/beyond_form_builder.rb
beyond_canvas-0.2.1.pre app/form_builders/beyond_form_builder.rb
beyond_canvas-0.2.0.pre app/form_builders/beyond_form_builder.rb