Florian Gilcher
2007-Apr-09 11:15 UTC
How do i switch off error wrapping for a specific field?
Hi, i have some issues with the default rails error wrapping. It wraps
errors in a div with class ''fieldsWithError'', which is not
good practice
in my eyes. Adding a class ''error'' to the field would be much
nicer.
My solution to the problem: build your own FormBuilder. Funny enough, i
found no (nice) possibility to switch error wrapping off while using the
FormHelper methods. As error_wrapping is a method in InstanceTag (and
not of FormHelper), it is pretty hard to have a FormBuilder change its
behaviour.
One possibility is to define
def initialize(object_name, object, template, options, proc)
ActionView::Base.field_error_proc = lambda do |html_tag, instance|
html_tag
end
super(object_name, object, template, options, proc)
end
which works, but i consider it an unclean solution (as it would change
the error_proc for the whole interpreter run). Consider the case where i
use another proc for my fields but the above version of the proc for my
form - the above version would change the behaviour of all following
fields.
Another version would be to redefine InstanceTag.error_wrapping to be
empty with the same method (not nice, eighter - same Argument).
Is there a nice way to have InstanceTags ignore errors (like
:ignore_errors => true) so that i can implement them myself (a trivial
problem inside a FormBuilder). I searched the code, but I find no
convinient way. Any hints would be much appreciated.
Thanks in advance
Florian
P.S.: Optional question: Is there a plugin that handles forms like Agavi
( www.agavi.org )? Aside from it being a PHP Framework (yuk!), I do
really like the form processing by filtering the output instead of doing
it explicitly with builders. Customizing forms in rails still seems to
be a bit of work to me :/.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Apr-09 15:28 UTC
Re: How do i switch off error wrapping for a specific field?
Or you could just add
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
"<span class=\"error\">#{html_tag}</span>"
end
to your config/environment.rb. I agree that using a div [block] where a span
[inline] would work as well seems overkill but I didn''t create Rails.
And
granting how awesome all the other stuff is, I think I''ll let this one
slide. ;)
RSL
On 4/9/07, Florian Gilcher
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hi, i have some issues with the default rails error wrapping. It wraps
> errors in a div with class ''fieldsWithError'', which is
not good practice
> in my eyes. Adding a class ''error'' to the field would be
much nicer.
>
> My solution to the problem: build your own FormBuilder. Funny enough, i
> found no (nice) possibility to switch error wrapping off while using the
> FormHelper methods. As error_wrapping is a method in InstanceTag (and
> not of FormHelper), it is pretty hard to have a FormBuilder change its
> behaviour.
>
> One possibility is to define
>
> def initialize(object_name, object, template, options, proc)
> ActionView::Base.field_error_proc = lambda do |html_tag, instance|
> html_tag
> end
> super(object_name, object, template, options, proc)
> end
>
> which works, but i consider it an unclean solution (as it would change
> the error_proc for the whole interpreter run). Consider the case where i
> use another proc for my fields but the above version of the proc for my
> form - the above version would change the behaviour of all following
> fields.
>
> Another version would be to redefine InstanceTag.error_wrapping to be
> empty with the same method (not nice, eighter - same Argument).
>
> Is there a nice way to have InstanceTags ignore errors (like
> :ignore_errors => true) so that i can implement them myself (a trivial
> problem inside a FormBuilder). I searched the code, but I find no
> convinient way. Any hints would be much appreciated.
>
> Thanks in advance
> Florian
>
> P.S.: Optional question: Is there a plugin that handles forms like Agavi
> ( www.agavi.org )? Aside from it being a PHP Framework (yuk!), I do
> really like the form processing by filtering the output instead of doing
> it explicitly with builders. Customizing forms in rails still seems to
> be a bit of work to me :/.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Florian Gilcher
2007-Apr-09 15:45 UTC
Re: How do i switch off error wrapping for a specific field?
Well, i already mentioned this ;). However, i found a method that does
just what i want (leave error handling to me for _just this builder_) it
may be a bit brutal, too, but it works just as i want:
class ErrorlessFormBuilder < FormBuilder
def initialize(object_name, object, template, options, proc)
super(object_name, object, template, options, proc)
end
def wrap_proc_with_error_deactivation(proc)
lambda do |html_tag, instance|
old_proc = ActionView::Base.field_error_proc
ActionView::Base.field_error_proc = lambda do |html_tag, instance|
html_tag
end
yield proc(html_tag, instance)
ActionView::Base.field_error_proc = old_proc
end
end
end
As we do not have to worry about thread safety, this is okay :). Thanks
for the help.
I do think that rails is great, too ;). It gives me the possibility to
wrap the form proc in a proc... do that in PHP or Java ;).
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Apr-09 15:59 UTC
Re: How do i switch off error wrapping for a specific field?
You know, you _did_ mention that. Only I would have had to actually looked at your code and not mentally compared the length of it to the length of that one I posted. Oopsie? RSL On 4/9/07, Florian Gilcher <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Well, i already mentioned this ;). However, i found a method that does > just what i want (leave error handling to me for _just this builder_) it > may be a bit brutal, too, but it works just as i want: > > class ErrorlessFormBuilder < FormBuilder > def initialize(object_name, object, template, options, proc) > super(object_name, object, template, options, proc) > end > > def wrap_proc_with_error_deactivation(proc) > lambda do |html_tag, instance| > old_proc = ActionView::Base.field_error_proc > ActionView::Base.field_error_proc = lambda do |html_tag, instance| > html_tag > end > yield proc(html_tag, instance) > ActionView::Base.field_error_proc = old_proc > end > end > end > > As we do not have to worry about thread safety, this is okay :). Thanks > for the help. > > I do think that rails is great, too ;). It gives me the possibility to > wrap the form proc in a proc... do that in PHP or Java ;). > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Florian Gilcher
2007-Apr-09 16:07 UTC
Re: How do i switch off error wrapping for a specific field?
Happens ;). Thanks for the bounce, my example code above has an error.
The constructor has to read:
def initialize(object_name, object, template, options, proc)
wrap_proc_with_error_deactivation(proc)
super(object_name, object, template, options, proc)
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---