Hello, Previously, I''ve been doing all my active record error feedback in forums by using ActionView::Base.field_error_proc. However, it is somewhat inflexible. I''ve also recently started to "get" custom form builders and am liking them. It really feels like the error wrapping should go into the form builders in order to obtain the greatest amount of ease / flexibility. I tried to do it this way, but it didn''t come out feeling "right". I was wondering if anybody else has done this or might have some suggestions / feedback on what I did. http://pastie.caboo.se/41081 Thanks, -carl -- EPA Rating: 3000 Lines of Code / Gallon (of coffee) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Carl Lerche
2007-Feb-18 22:55 UTC
Re: Moving AR object error wraping to custom FormBuilders
Nobody has tried to do this before? On 2/17/07, Carl Lerche <carl.lerche-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > Previously, I''ve been doing all my active record error feedback in > forums by using ActionView::Base.field_error_proc. However, it is > somewhat inflexible. I''ve also recently started to "get" custom form > builders and am liking them. It really feels like the error wrapping > should go into the form builders in order to obtain the greatest > amount of ease / flexibility. > > I tried to do it this way, but it didn''t come out feeling "right". I > was wondering if anybody else has done this or might have some > suggestions / feedback on what I did. > > http://pastie.caboo.se/41081 > > Thanks, > -carl > > -- > EPA Rating: 3000 Lines of Code / Gallon (of coffee) >-- EPA Rating: 3000 Lines of Code / Gallon (of coffee) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Schuerig
2007-Feb-19 02:27 UTC
Re: Moving AR object error wraping to custom FormBuilders
On Sunday 18 February 2007, Carl Lerche wrote:> Nobody has tried to do this before?http://www.agilewebdevelopment.com/plugins/label_helpers Not a form builder, but you can presumably use the same technique. HTH, Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can''t connect to the website of the repository. Is this plugin defunct? Shauna -- 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 -~----------~----~----~----~------~----~------~--~---
Michael Schuerig
2007-Feb-21 01:04 UTC
Re: Moving AR object error wraping to custom FormBuilders
On Wednesday 21 February 2007, Shauna wrote:> Can''t connect to the website of the repository. Is this plugin > defunct?I have no idea, but a local copy :-) See below for label_helper.rb HTH, Michael http://www.eric-stewart.com/blog/articles/2006/01/13/label-me-please # Helpers for generating label tags for inputs # # Includes some support for accessibility techniques # module ActionView module Helpers module FormHelper # Returns a label tag tailored for describing a specified attribute (identified by +method+) on an object # assigned to the template (identified by +object+). Additional options on the tag can be passed as a # hash with +options+. # # Examples (call, result): # label("post", "title", "Post Title", :class => "foo") # <label for="post_title" class="foo">Post Title</label> def label(object, method, label_text = nil, options = {}) label_text ||= "#{method.titleize}:" InstanceTag.new(object, method, self).to_label_tag(label_text, options) end end module FormTagHelper # Creates a standard label for a field. # # Options: # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input. # * <tt>:hide_errors</tt> - If set to false, the label will append validation errors for the object # it is a label for # A hash of standard HTML options for the tag. def label_tag(for_id, value = nil, options = {}) options.stringify_keys! if !options.has_key?(''for'') options[''for''] = for_id end content_tag("label", value, options) end end class InstanceTag #:nodoc: def to_label_tag(label_text, options = {}) error_string = "" options["for"] ||= "#{tag_id}" if options.has_key?(''hide_errors'') options.delete(''hide_errors'') else error_string = " <em>#{error_message}</em>" end content_tag "label", "#{label_text}#{error_string}", options end # This new error_wrapping method prevents a label that is being generated # for an object/field from being wrapped by an error div. Only the input # tag itself should be wrapped. alias_method :original_error_wrapping, :error_wrapping def error_wrapping(html_tag, has_error) if [''label''].detect { |tag| html_tag.starts_with?("<#{tag}") } return html_tag end original_error_wrapping html_tag, has_error end end end end -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Michael. Open source is great! Shauna -- 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 -~----------~----~----~----~------~----~------~--~---