Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea misses the first line if empty #238

Closed
phoenixyjll opened this issue Dec 31, 2015 · 3 comments · Fixed by #395
Closed

Textarea misses the first line if empty #238

phoenixyjll opened this issue Dec 31, 2015 · 3 comments · Fixed by #395

Comments

@phoenixyjll
Copy link

@phoenixyjll phoenixyjll commented Dec 31, 2015

When saving a textarea with the first line empty (leading line break), the browser won't show that line after viewing the changed form, but the data sent to the server is correct. And then we save it again with nothing changed, data sent to the server also misses that line.

@crast crast added the waiting label Feb 19, 2016
@crast
Copy link
Contributor

@crast crast commented Feb 19, 2016

Do you have an example of this?

I do not have a reproducible example of this

@phoenixyjll
Copy link
Author

@phoenixyjll phoenixyjll commented Mar 3, 2016

  1. Create a TextAreaField, and render it in HTML.
  2. Input something in the textarea with the first line empty. e.g. "\r\nabc".
  3. Submit the form. The webpage is refreshed.
  4. The first empty line misses in the textarea.

@davidism
Copy link
Member

@davidism davidism commented Jun 4, 2018

The HTML spec is surprisingly vague about this, but it looks like browsers strip an initial \r\n, and other frameworks account for this by adding one during rendering.

quis added a commit to alphagov/notifications-admin that referenced this issue Apr 23, 2020
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to do this. Instead this commit makes our
own `EmailField`, which just handles rendering the field as an email
field, not validating that (because we add the validation elsewhere).

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. wtforms/wtforms#429
2. wtforms/wtforms#238
3. https://design-system.service.gov.uk/components/radios/#error-messages
quis added a commit to alphagov/notifications-admin that referenced this issue Apr 23, 2020
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to do this. Instead this commit makes our
own `EmailField`, which just handles rendering the field as an email
field, not validating that (because we add the validation elsewhere).

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. wtforms/wtforms#429
2. wtforms/wtforms#238
3. https://design-system.service.gov.uk/components/radios/#error-messages
quis added a commit to alphagov/notifications-admin that referenced this issue Apr 23, 2020
This involves three changes which broke our code.

To validate email addresses, the optional dependency `email-validator`
must be installed<sup>1</sup>. But since we don’t use WTForms’ email
validation, we shouldn’t need to subclass it – it can just be its own
self contained thing. Then we don’t need to add the extra dependency.

When rendering textareas, and extra `\r\n` is inserted at the beginning
<sup>2</sup>. Browsers will strip this when displaying the textbox and
submitting the form, but some of our tests need updating to account for
this.

The error message for when you don’t choose an option from some radio
buttons has now changed. Rather than just accepting WTForms’ new
message, this commit makes the error messages like the examples from
the Design System<sup>3</sup>. By default it will say ‘Select an
option’, but by passing in an extra parameter (`thing`) it can be
customised to be more specific, for example ‘Select a type of
organisation’.

***

1. wtforms/wtforms#429
2. wtforms/wtforms#238
3. https://design-system.service.gov.uk/components/radios/#error-messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants