Sha256: ed98d73050ab15d2ad82d846cf12afc882a311351df490c7d2d31d9cbef62ed9

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Effective
  module FormInputs
    class ErrorField < Effective::FormInput

      def input_html_options
        { class: 'alert alert-danger', id: tag_id }
      end

      def to_html(&block)
        return nil unless has_error?(name)

        case layout
        when :horizontal
          build_wrapper do
            content_tag(:div, '', class: 'col-sm-2') + content_tag(:div, build_error_content, class: 'col-sm-10')
          end
        else
          content_tag(:div, build_error_content, class: 'form-group')
        end
      end

      def build_error_content
        include_name = include_name?

        content = (
          if name.blank?
            object.errors.full_messages.to_sentence
          elsif include_name?
            object.errors.full_messages_for(name).to_sentence
          else
            object.errors.messages[name].to_sentence
          end
        )

        content_tag(:div, content.html_safe, options[:input])
      end

      private

      def include_name?
        return @include_name unless @include_name.nil?
        @include_name = options[:input].key?(:include_name) ? options[:input].delete(:include_name) : true
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
effective_bootstrap-0.9.47 app/models/effective/form_inputs/error_field.rb