Ruby on Rails Thursday, December 30, 2010

Does anybody know a good way to completely customize validation
output? I've tried a number of options but can only get partway there.

For example I'd like to style not only the affected form input but
also its label, and provide a message (common to many apps). This has
been problematic, as the input is referenced internally by 'html_tag'
and at that point its associated label is out of scope:

http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#customizing-the-error-messages-html

I've added the message using this method but can't get at the label.

I've also created an auto-labeling form builder (http://
edgeguides.rubyonrails.org/form_helpers.html#customizing-form-
builders) but the error handling still only grabs the input itself
after the form has been built (i.e., it doesn't view my custom labeled
input as a sort of composite control).

I can accomplish this in the view conditionally by checking
@instance.errors on a per-field basis, but this seems clunky. And if I
do that, doesn't all the validation stuff still fire internally,
burning cycles on something I don't use?

There must be a good way to automate this.

--
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@googlegroups.com.
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.

No comments:

Post a Comment