Opened 5 years ago

Closed 3 years ago

#13385 closed Bug (duplicate)

Wrong behavior for textarea tag render

Reported by: williambr 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)

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 williambr 5 years ago.
Textarea render
textarea-trunk.diff (600 bytes) - added by williambr 5 years ago.
textarea patch for svn trunk
ticket13385.patch (8.2 KB) - added by akaariai 5 years ago.
patch with tests
13385.diff (9.9 KB) - added by claudep 4 years ago.
Patch updated to current trunk

Download all attachments as: .zip

Change History (16)

comment:1 Changed 5 years ago by ramiro

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

(reformatted description)

comment:2 Changed 5 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to closed

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 5 years ago by williambr

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 5 years ago by russellm

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by williambr

Textarea render

comment:5 Changed 5 years ago by williambr

OK.

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

Changed 5 years ago by williambr

textarea patch for svn trunk

comment:6 Changed 5 years ago by gabrielhurley

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 5 years ago by akaariai

patch with tests

comment:7 Changed 5 years ago by akaariai

  • Needs tests unset
  • Patch needs improvement unset

comment:8 Changed 5 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 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:10 Changed 4 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

ticket13385.patch fails to apply cleanly on to trunk

Changed 4 years ago by claudep

Patch updated to current trunk

comment:11 Changed 4 years ago by claudep

  • Patch needs improvement unset
  • UI/UX unset

comment:12 Changed 3 years ago by claudep

  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #8627, which has just been fixed.

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