Overriding <div class="fieldWithErrors">


#1

Does anyone know how to override the


behaviour when a form field is incorrect?

Thanks,
Dan


#2

On Sat, Mar 25, 2006 at 01:22:05PM +1100, Dan H. wrote:

Does anyone know how to override the


behaviour when a form field is incorrect?

This is what ActionView does:

module ActionView
class Base
@@field_error_proc = Proc.new{ |html_tag, instance| “<div
class=“fieldWithErrors”>#{html_tag}

” }
cattr_accessor :field_error_proc
end
end

You can set your own Proc. For example, in your config/environment.rb:

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
%(#{html_tag})}

marcel


#3

Some more information may help. Having the “div” tags makes my HTML
invalid, so instead a “span” tag would be more appropriate.

Thanks,
Dan


#4

Marcel Molina Jr. wrote:

You can set your own Proc. For example, in your config/environment.rb:

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance| %(#{html_tag})}

Cool thanks. That worked a treat.

Dan


#5

Ben M. wrote:

Let me guess… inside a td, right?

b

Actually no, it was inside a

. I was using

to group form
sections together.

Dan


#6

It needs a little tweak to make this work on rails 3, since it now
protects all strings against XSS attacks(i.e. html escapes them).

The following works:
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
’.html_safe << html_tag <<
’.html_safe
end

Obs.: dunno if there isn’t a better way of doing this on rails 3.

Marcel Molina Jr. wrote:

On Sat, Mar 25, 2006 at 01:22:05PM +1100, Dan H. wrote:

Does anyone know how to override the


behaviour when a form field is incorrect?

This is what ActionView does:

module ActionView
class Base
@@field_error_proc = Proc.new{ |html_tag, instance| “<div
class=“fieldWithErrors”>#{html_tag}

” }
cattr_accessor :field_error_proc
end
end

You can set your own Proc. For example, in your config/environment.rb:

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
%(#{html_tag})}

marcel


#7

Let me guess… inside a td, right?

b


#8

Dan H. wrote:

Ben M. wrote:

Let me guess… inside a td, right?

b

Actually no, it was inside a

. I was using

to group form
sections together.

Well, you don’t have to use error_messages_for (which generated the

) to print your errors, and you don't have to put your
somewhere where it will lead to invalid HTML. is probably semantically inappropriate. > > Dan Best, -- Marnen Laibow-Koser http://www.marnen.org removed_email_address@domain.invalid