Re: TEXTAREA and white space, CR

On Thu, 22 Apr 2004 guenther.grau@ubs.com wrote:

> I have a question regarding TEXTAREA and white space, in particular
> CRs.

Briefly, what the specifications say has largely been overruled by
implementations, so that you now need a nonstandard attribute (wrap="off")
if you want to make browsers behave according to the "standard". See
http://www.cs.tut.fi/~jkorpela/forms/textarea.html#wrap for an overview
(somewhat dated, but paints the big picture, I hope).

> I'd like to display a text that starts with a CR in a TEXTAREA.

Oh. The TEXTAREA element is for user input. There's no prohibition against
using it for data display, but you should expect its implementation
reflect is meaning and purpose.

> So, what should conforming HTML look like to display a text starting
> with a CR in a TEXTAREA?

They need not display it at all. But if they are visual user agents, they
are expected to honor line breaks, including CR, so they should display an
initial empty line in that case.

> <textarea>
>
> test
> </textarea>
>
> seems to work for IE6/NS7, but doesn't in Opera 7.11.

Could be a bug in 7.11. My Opera 7.23 shows an empty line.

> And, as a more general note, aren't user agents supposed to
> collapse all sequences of white spaces also in a textarea
> according to section 9.1, making it impossible to display
> a preset text in a TEXTAREA that contains multiple spaces?

It says "For all HTML elements except PRE", but apparently it should be
"PRE and TEXTAREA". Just an oversight I guess. It is crucial for the very
purpose of TEXTAREA to accept user input as such and transmit it, and it
would be highly unnatural to display spaces as collapsed when they must be
kept uncollapsed in the actual data to be sent. As a side effect, any
initial data in the TEXTAREA element should be treated the same way,
obviously, especially since it too will be actually sent as such, unless
changed by the user.

Strangely enough, the sample style sheet for HTML 4.0 in the CSS 2 spec,
http://www.w3.org/TR/REC-CSS2/sample.html
contains
PRE             { white-space: pre }
but nothing (!) for TEXTAREA. Another oversight, I guess.

I'm afraid we just have to acknowledge that
a) the implementations do not handle newlines as described in the spec
b) there's an oversight in describing how whitespace is handled is
TEXTAREA
c) people are probably not interested in improving the HTML 4
specifications, since work is directed towards the XHTML 2 activity, which
means that HTML forms will be dropped out in favor of the XForms
construct (which we might enjoy in the wild in the 2010s, I'd estimate).

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/

Received on Thursday, 22 April 2004 06:38:41 UTC