If a model doesn''t pass validation the field in the view is put under a <div class="field_with_errors">. But who create that div? field_text helper do it? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello Mauro, <div class="field_with_errors"> tag is created in ActionView::Base class only in case of any errors. From Rails code base:- # Specify the proc used to decorate input tags that refer to attributes with errors. cattr_accessor :field_error_proc @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe } Thanks! Butu On Sat, Oct 2, 2010 at 2:07 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If a model doesn''t pass validation the field in the view is put under > a <div class="field_with_errors">. > But who create that div? field_text helper do it? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 October 2010 04:05, Butu <butu25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Mauro, > > <div class="field_with_errors"> tag is created in ActionView::Base > class only in case of any errors. > > From Rails code base:- > > # Specify the proc used to decorate input tags that refer to > attributes with errors. > cattr_accessor :field_error_proc > @@field_error_proc = Proc.new{ |html_tag, instance| "<div > class=\"field_with_errors\">#{html_tag}</div>".html_safe } > > Thanks! > Butu....and if I don''t want those divs? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 5 October 2010 08:07, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5 October 2010 04:05, Butu <butu25-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hello Mauro, >> >> <div class="field_with_errors"> tag is created in ActionView::Base >> class only in case of any errors. >> >> From Rails code base:- >> >> # Specify the proc used to decorate input tags that refer to >> attributes with errors. >> cattr_accessor :field_error_proc >> @@field_error_proc = Proc.new{ |html_tag, instance| "<div >> class=\"field_with_errors\">#{html_tag}</div>".html_safe } >> >> Thanks! >> Butu > > ....and if I don''t want those divs?For my education, why would you object to them being there? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, If you have your own way of handling errors in your views, you can disable rails default encapsulation by doing ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| html_tag end inside an initializer. and so no "field_with_errors" div will be wrapped around your fields. On Oct 5, 10:27 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 5 October 2010 08:07, Mauro <mrsan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 5 October 2010 04:05, Butu <but...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello Mauro, > > >> <div class="field_with_errors"> tag is created in ActionView::Base > >> class only in case of any errors. > > >> From Rails code base:- > > >> # Specify the proc used to decorate input tags that refer to > >> attributes with errors. > >> cattr_accessor :field_error_proc > >> @@field_error_proc = Proc.new{ |html_tag, instance| "<div > >> class=\"field_with_errors\">#{html_tag}</div>".html_safe } > > >> Thanks! > >> Butu > > > ....and if I don''t want those divs? > > For my education, why would you object to them being there? > > Colin-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > ....and if I don''t want those divs? > > For my education, why would you object to them being there?Something that has bothered me from time to time is that when there are errors the <div> tag takes the whole line and makes the field to end up in the next line, instead of appearing next to its label. Another thing that annoys me is that if I create labels using the form object (f.label ...) the label is also marked as in error, for that reason only I don''t use the form object to create labels. I have never had the time to look for a solution but there might be an easy one. It would be nice if one could choose between <div> and <span>, for example. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pepe wrote:>> > ....and if I don''t want those divs? >> >> For my education, why would you object to them being there? > > Something that has bothered me from time to time is that when there > are errors the <div> tag takes the whole line and makes the field to > end up in the next line, instead of appearing next to its label. > Another thing that annoys me is that if I create labels using the form > object (f.label ...) the label is also marked as in error, for that > reason only I don''t use the form object to create labels. > > I have never had the time to look for a solution but there might be an > easy one. It would be nice if one could choose between <div> and > <span>, for example..field_with_errors { display: inline; } That should do the trick. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> .field_with_errors { > display: inline; > > } > > That should do the trick.Thanks Marnen. I''ll try that. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> .field_with_errors { > display: inline; > > }Just tried it and worked as expected. Thanks Marnen. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- Overriding <div class="fieldWithErrors">
- Getting Rid of Error Divs around fields that have errors
- How do i switch off error wrapping for a specific field?
- TIP: Using field_error_proc to add style attributes to form elements
- How to override generated in validation html code?