Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2210 (closed defect: wontfix)

Opened 5 years ago

Last modified 3 years ago

[patch] error_message_on should use SPAN not DIV

Reported by: jerry.west@ntlworld.com Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version: 0.13.1
Severity: minor Keywords: form error helper span div formError fieldWithErrors error_messages_on field_error_proc
Cc:

Description

error_message_on() and field_error_proc should return an HTML span and not an HTML div.

A form will often place error_message_on() inline with some text - the label for the field, perhaps. But browsers are entitled to surround DIVs, as block-level structures, with line-breaks. (See HTML spec). IE, in particular, does so, messing Rails' reputation for 'out-of-the-box' functionality.

Yes, the unwanted line-breaks can be removed by various css hacks but it's not intuitive and (IMHO) a real waste of a developer's time.

Summary: the developer can surround a SPAN with a DIV if they want, but it's much more difficult to neutralise a DIV if you don't want it.

Besides which, a SPAN is The Right Thing To Do(tm) if the content of the generated error tag is simply text - there's no block structure to enclose.

PS: I would probably also argue that the form helpers should surround their fieldWithErrors with a SPAN - there is no hierarchical structure there either and form elements are inline not block. I vote to change field_error_proc too.

Attachments

active_record_helper_use_span.patch (1.2 kB) - added by foamdino@gmail.com on 09/22/05 03:11:20.
small patch that selects span tag if use_span is true

Change History

09/16/05 11:09:40 changed by madrobby

I concur that it is probably better to use SPAN elements, but... this will break backwards-compatibility for all those who already use self-made stylsheets.

Besides it's really not a "CSS hack", but a one liner to change the behaviour: div.someclass { display:inline; } 

So I'd vote to leave this as-is.

09/16/05 16:17:09 changed by jerry.west@ntlworld.com

Re - display:inline is fix

True, but you also have to have the surrounding container set as display:inline for it to work in IE6. Which means your vertical spacing is now totally messed up on the blank form (no gaps between paragraphs) unless you are using tables.

And if you allow backwards compatibility to determine your bug-fix policy, you are on a long and very slippery slope! But a compromise: error_messages_on() acts as now, but the error_messages_on(:span, ...) does the obvious thing.

Cheers,

Jerry

09/17/05 06:35:23 changed by anonymous

  • component changed from ActiveRecord to ActionPack.

09/22/05 03:11:20 changed by foamdino@gmail.com

  • attachment active_record_helper_use_span.patch added.

small patch that selects span tag if use_span is true

09/22/05 03:11:58 changed by anonymous

  • summary changed from error_message_on should use SPAN not DIV. to [patch] error_message_on should use SPAN not DIV..

10/03/05 18:47:41 changed by Goynang

This effects the form helpers too. You can't put DIV tags inside P tags - it's invalid HTML. You can't fix it with CSS.

The current state of affairs means you effectively can't use P tags around form fields created by the helpers. Unless I'm missing something this has got a be bad. I vote for making it all configurable by options (tag to use, classes to set, etc.) with the defaults as now for backwards compatibility.

10/07/05 12:30:27 changed by anonymous

Yeah, the use of DIVs for fieldWithErrors definitely breaks our site's HTML validation. Goynang's right; this isn't just a problem in error_message_on.

10/10/05 00:33:18 changed by marcel

  • status changed from new to closed.
  • resolution set to wontfix.

You can customize this yourself. From actionpack/lib/action_view/helpers/active_record_helper.rb:

module ActionView
  class Base
    @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" }
    cattr_accessor :field_error_proc
  end

In, e.g., your config/environment.rb, you can do, e.g.:

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|  %(<span class="field-with-errors">#{html_tag}</div>)}

10/14/05 23:08:59 changed by hendrik@mans.de

  • status changed from closed to reopened.
  • resolution deleted.

What marcel proposed when he closed the ticket was unrelated to this ticket. This ticket is about error_message_on() using DIVs, not fields with errors.

I request an additional parameter to be introduced to error_message_on() that allows us to specify either one of the following:

  • a different HTML tag to be used
  • prepend/append HTML
  • a Proc that produces the HTML

Thanks, and please forgive me for reopening this ticket.

08/18/06 15:10:44 changed by kastberg@tkwsping.nl

  • keywords changed from rthml tab space editor js to form error helper span div formError fieldWithErrors error_messages_on field_error_proc.
  • severity changed from critical to minor.
  • summary changed from hi-world cup to [patch] error_message_on should use SPAN not DIV.

05/06/07 20:47:58 changed by josh

  • status changed from reopened to closed.
  • resolution set to wontfix.