Sha256: 05f327e6bdad11ff99deed4af05c3efd6a8d46fc762ceb94269631566caf7d05

Contents?: true

Size: 1.15 KB

Versions: 137

Compression:

Stored size: 1.15 KB

Contents

module Effective
  module FormInputs
    class ErrorField < Effective::FormInput

      def input_html_options
        { class: 'alert alert-danger' }
      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, 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

137 entries across 137 versions & 1 rubygems

Version Path
effective_bootstrap-0.3.9 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.8 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.7 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.6 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.5 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.4 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.3 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.2 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.1 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.3.0 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.2.4 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.2.3 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.2.2 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.2.1 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.2.0 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.1.12 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.1.11 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.1.10 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.1.9 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.1.8 app/models/effective/form_inputs/error_field.rb