Sha256: bccdd20c8d5515af71fbbac306291e7011f491939aaa9b678e3ac783d48cae6c

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module JqueryUiForm 
  module Helpers
    module ErrorHelper
      
      def has_errors?(method)
        @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
      end
      
      def error_message_on(method)
        @object.errors[method.to_sym].join(" #{use_i18n ? I18n.t('and') : 'and'} ")
      end
      
      def error_messages_on_base
        @object.errors[:base].join(" #{use_i18n ? I18n.t('and') : 'and'} ")
      end
      
      def inline_error(method)
        return "" unless has_errors?(method)
        template.content_tag(:div, error_message_on(method), :class => "ui-input-error-message")
      end
      
      def model_errors(errors=[])
        errors = error_messages_on_base.to_a + errors.to_a
        return "" if errors.empty?
        template.content_tag(:div, :class => "ui-base-error-messages") do
          errors.each do |message|
            template.concat(
              template.content_tag(:p) do
                template.concat(template.content_tag(:span, "", :class => "ui-icon ui-icon-alert"))
                template.concat(template.content_tag(:strong, message))
              end
            )
          end
        end
      end
                
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jquery-ui-form-0.1.5 lib/jquery_ui_form/helpers/error_helper.rb