Does anyone know how to override the
behaviour when a form field is incorrect?
Thanks,
Dan
Does anyone know how to override the
Thanks,
Dan
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
endYou 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
Some more information may help. Having the “div” tags makes my HTML
invalid, so instead a “span” tag would be more appropriate.
Thanks,
Dan
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
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
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
endYou 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
Let me guess… inside a td, right?
b
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs