bastihilger / nova-tiptap

Laravel Nova Tiptap Field
MIT License
172 stars 61 forks source link

Field saving empty HTML tags on removal #11

Closed doriandigital closed 4 years ago

doriandigital commented 4 years ago

Hi Magoni,

First of all, thank you so much for this amazing package!

One small thing, I noticed that when deleting all the text inside the field editor, empty HTML tags are still saved on the database.

Things like <p></p> or <strong></strong>.

The problem is, when doing <?php if (empty($field)) echo 'something'; ?> is always going to give positive, because $field is never really "empty".

bastihilger commented 4 years ago

Hi @doriandigital , I think this is a problem not unique to TipTap. Other editors have the same "feature" (not really a "bug"), where they enter an empty paragraph when the page is empty.

For now there is no way for me to change this, as this is the behavior of the underlying editor - I only wrote the Nova wrapper (so most of your thanks goes to @scrumpy ;-))

I would always have a bit more robust check when checking if a value coming from an editor is "empty", more like

if (!trim(strip_tags($field)))

Or even write a little custom helper method like html_field_is_empty.

Thanks for commenting, but I will close this issue now.

doriandigital commented 4 years ago

Hi @doriandigital , I think this is a problem not unique to TipTap. Other editors have the same "feature" (not really a "bug"), where they enter an empty paragraph when the page is empty.

For now there is no way for me to change this, as this is the behavior of the underlying editor - I only wrote the Nova wrapper (so most of your thanks goes to @scrumpy ;-))

I would always have a bit more robust check when checking if a value coming from an editor is "empty", more like

if (!trim(strip_tags($field)))

Or even write a little custom helper method like html_field_is_empty.

Thanks for commenting, but I will close this issue now.

Makes total sense! Thank you for looking into it :)