Closed mmikkel closed 2 years ago
@mmikkel Is it saved with a <br>
or <br/>
inside?
Here's the relevant part of the payload for the actions/entry-revisions/save-draft
request that triggers when the field is emptied – looks like it's saved as <p><br></p>
:
Here's a quick screencast, if it helps:
https://user-images.githubusercontent.com/298510/161071315-86f1f491-f9ee-457f-a1a1-00c54fc2b8b7.mp4
I understand the issue, I just don't get why it's not being cleared up.
Any chance you could add some debugging code around these parts? It should be taking care of this so I'm just a little perplexed.
I think it's due to some trailing whitespace in the value submitted from the Redactor field, so the conditional at https://github.com/craftcms/html-field/blob/fd3d400643fccbe27583102f581640f465987a06/src/HtmlField.php#L94 evaluates to false
.
If I add a simple trim()
to the $value
, it works as expected, i.e.
if (in_array(\trim($value), ['<p><br></p>', '<p> </p>'], true)) {
return null;
}
Fixed via craftcms/html-field
v1.0.7 and 2.0.2.
Description
I'm seeing some odd/unwanted behaviour when authors attempt to clear/empty Redactor fields.
If an author clears out a Redactor field by first selecting all the text (i.e. Cmd+A) and then hitting the backspace button, the field value stored is always NULL (which is expected/wanted behaviour).
However, if a field contains multiple paragraphs, and the author clears out the field without first selecting all the text – for example, by putting the caret after the last character and then holding down backspace until the field is empty – the value stored will be an empty
<p>
tag with a single linebreak, i.e. this:Visually, the Redactor field appears empty after saving, and if the entry is re-saved again (without touching the field) the empty
<p>
appears to be removed. But, this isn't something that is easy for authors to catch, and results in a lot of{% if entry.text %}
template conditionals evaluating totrue
, even if there isn't actually any content in the field.Steps to reproduce
<p>
tag with a single<br/>
inside.Additional info