Marking up errors on forms.

The form helpers by default wrap fields with errors in a div with an appropriate class. Unfortunately this means that you can't place these in <p> tags which many do (including for example the rails scaffold). It is a simple change to generate spans instead of divs (or generally make any sort of change that seems appropriate).

This may break the appearance of your app, whether it's because of style rules attached to div.fieldWithErrors that will no longer apply or because the styles that previously applied to broken html look different on correct html. Unfortunately this is the sort of breakage that is hard to verify automatically. So it seems there are three ways forward (not counting the 'do nothing' way:

- change the default settings to generate spans. It's not hard for you to change it back to divs in an initializer or something if you need it the old way - leave the current defaults but have a span based markup in the rails3_new_defaults initializer so that new apps will get 'good' behaviour - the current code sucks and it would be much nicer to have this sort of stuff controller by the form builder rather than some setting on ActionView::Base (and once you've done that rewrite then you still have to decide what actual markup is generated by default)

Opinions appreciated (assuming you're not drunk on christmas cheer)

Fred

Ticket is here #1626 fieldWithErrors shouldn't use a div - Ruby on Rails - rails

The insertion of the div only when errors are present is a real pain. It would be a lot easier to write CSS to style the forms if the div (or span) was there even when there weren't errors, and then changed class depending on whether there was an error. I don't think div vs span is a big deal since you can style them to be inline or block as you choose. Usually I end up writing my own form builder class so this stuff isn't an issue for me, but the times when I do end up using the default form builder my CSS always gets super ugly.

I'm not familiar with how the Merb form generator does things. Maybe it's time for a look.

Completely agree with Frederick's initiative to clean this up.

Letting the form builder control the error markup is appropriate. A default configuration that renders a shared partial for errors might be a good approach -that would allow customization of layout without customization of code.

Otherwise, I like Josh's suggestion of having the structure remain constant (divs/spans present) is a good idea

-Chris