Opened 6 years ago

Closed 4 years ago

#13385 closed Bug (duplicate)

Wrong behavior for textarea tag render

Reported by: William Grzybowski Owned by: nobody
Component: Forms Version: 1.1
Severity: Normal Keywords: textarea form
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

The Textarea widget is rendering textarea tag like this:

return mark_safe(u'<textarea%s>%s</textarea>' % (flatatt(final_attrs),
                conditional_escape(force_unicode(value))))

However this is not the expected behavior for textarea tag, as from W3C[1] this should be:

<textarea>
first line
</textarea>

So the correct render should be:

return mark_safe(u'<textarea%s>\n%s\n</textarea>' % (flatatt(final_attrs),
                conditional_escape(force_unicode(value))))

[1] http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA

Attachments (4)

textarea.patch (548 bytes) - added by William Grzybowski 6 years ago.
Textarea render
textarea-trunk.diff (600 bytes) - added by William Grzybowski 6 years ago.
textarea patch for svn trunk
ticket13385.patch (8.2 KB) - added by Anssi Kääriäinen 6 years ago.
patch with tests
13385.diff (9.9 KB) - added by Claude Paroz 5 years ago.
Patch updated to current trunk

Download all attachments as: .zip

Change History (16)

comment:1 Changed 6 years ago by Ramiro Morales

Description: modified (diff)
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

(reformatted description)

comment:2 Changed 6 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

I don't see anything in the reference you provide that requires that there be newlines inside the definition of a TEXTAREA, and I haven't seen any evidence that Django's rendering causes problems in any browers in practice.

comment:3 Changed 6 years ago by William Grzybowski

Resolution: invalid
Status: closedreopened

Sorry i forgot to mention.

The problem is like this:

  • Write a text using the widget Textarea starting with a newline, like: "\n My text here"
  • Save it
  • Come back to edit the saved the

You will not see the blank line in the start of the textarea

comment:4 Changed 6 years ago by Russell Keith-Magee

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Ok. I see what you're driving at now. However, it looks to me like only the first \n is required; if you have the trailing \n, you end up padding your submissions.

Tests are also required.

Changed 6 years ago by William Grzybowski

Attachment: textarea.patch added

Textarea render

comment:5 Changed 6 years ago by William Grzybowski

OK.

Patch reworked with heading \n.
Tested ok here, tell me if there is anything else to do, i am new here :)

Changed 6 years ago by William Grzybowski

Attachment: textarea-trunk.diff added

textarea patch for svn trunk

comment:6 Changed 6 years ago by Gabriel Hurley

FYI, by "tests are also required" Russell meant a regression test for the test suite (i.e. a unit test/doctest). That's what the "needs tests" checkbox on the ticket is for.

Changed 6 years ago by Anssi Kääriäinen

Attachment: ticket13385.patch added

patch with tests

comment:7 Changed 6 years ago by Anssi Kääriäinen

Needs tests: unset
Patch needs improvement: unset

comment:8 Changed 6 years ago by anonymous

Textarea tag should be rendered with cols="" and rows="" attributes, because it's needed by W3C validation.
I think it is obligate, event if those attributes are to be set to empty value.

comment:9 Changed 5 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:10 Changed 5 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set

ticket13385.patch fails to apply cleanly on to trunk

Changed 5 years ago by Claude Paroz

Attachment: 13385.diff added

Patch updated to current trunk

comment:11 Changed 5 years ago by Claude Paroz

Patch needs improvement: unset
UI/UX: unset

comment:12 Changed 4 years ago by Claude Paroz

Resolution: duplicate
Status: reopenedclosed

Duplicate of #8627, which has just been fixed.

Note: See TracTickets for help on using tickets.
Back to Top