Sha256: ba86352f6b2c5a21ff9b536a214a0a761a0fe4407e7914fa4254458492d4cb31

Contents?: true

Size: 1.17 KB

Versions: 53

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, 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

53 entries across 53 versions & 1 rubygems

Version Path
effective_bootstrap-0.9.46 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.45 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.44 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.43 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.42 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.41 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.40 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.39 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.38 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.37 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.36 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.35 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.34 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.33 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.32 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.31 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.30 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.29 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.28 app/models/effective/form_inputs/error_field.rb
effective_bootstrap-0.9.27 app/models/effective/form_inputs/error_field.rb