0

I have the following desired html (slim template):

li
    label
        span
            | Password
            small.error ERROR MESSAGE
        br
        = f.password_field :password

I wanna put the error (small.error) within the "span" above.

My solution (so far) is:

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    if instance.error_message.kind_of?(Array)
        %(#{html_tag}<small class="error">
        #{instance.error_message.join(',')}</small>).html_safe
    else
        %(#{html_tag}<small class="error">
        #{instance.error_message}</small>).html_safe
    end
end

But in this fashion the small tag has been placed right under the input tag.

Could I change that target location?

ylluminate
  • 12,102
  • 17
  • 78
  • 152
maiconsanson
  • 243
  • 3
  • 16
  • Similar question with answer: http://stackoverflow.com/questions/7341545/rails-actionviewbase-field-error-proc-moving-up-the-dom-tree/ – maiconsanson Aug 02 '12 at 20:58

1 Answers1

0

Problem solve with javascript:

$("small.error").each(function(){
    $(this).appendTo($(this).parent("label").find("span"));
});
maiconsanson
  • 243
  • 3
  • 16