Removed unnecessary NewLine from Textarea From Widget #5987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When building a form with Django and using a Textarea Widget, the value rendering is always prepended by a NewLine (
\r\n
).This makes the textarea never empty when it is, and changes the value for the following submissions.
This commit fixes this behaviour with just a trivial change.
Explanation:
When there is no (or an empty) value defined for the textarea, it shall be rendered as
and not as
At least in XHTML5 documents, this is a major difference.
Let's see what happens with a value:
This is currently rendered as this:
Which renders in the browser to:
After applying my patch, the rendering changes to this:
Which (correctly) renders in the browser to:
As a workaround to get around with the current implementation, I've overridden the
render
method of the original Widget class: