fix: preserve leading newlines in TextArea field (#732) - #767
Open
SHYXIN wants to merge 1 commit into
Open
Conversation
HTML spec: browsers ignore the first newline immediately after the
<textarea> opening tag. The original template used {% if data -%}
which trimmed whitespace, causing the textarea value to start directly
after <textarea> with no intermediate newline.
The fix removes the whitespace-trimming -%} and adds an explicit
newline + indented {{ data }} on the next line, so the browser
consumes the template's newline instead of the data's leading newline.
Before: <textarea...>{{ data }}</textarea> → "\n\nline2" becomes "\nline2"
After: <textarea...>\n{{ data }}</textarea> → "\n\nline2" is preserved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TextArea field values with leading newlines (e.g.
\n\nline2) lost the first newline when rendered in the edit form. This is because the HTML spec states that browsers ignore the first newline immediately after the<textarea>opening tag.Root Cause
The original template used
{% if data -%}with whitespace-trimming (-%}), which produced:When
datawas\n\nline2, the output was<textarea>\n\nline2</textarea>, and the browser consumed the first\n.Fix
starlette_admin/templates/forms/textarea.html— Removed whitespace-trimming and added an explicit newline before{{ data }}:Now the browser consumes the template's newline, preserving the data's leading newlines.
Testing