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

TextEditorField loses h3 heading configured with documented blockAttributes #5725

Closed
BurningDog opened this issue Apr 22, 2023 · 4 comments
Closed
Labels

Comments

@BurningDog
Copy link

BurningDog commented Apr 22, 2023

Describe the bug

I wanted to implement the blockAttributes config as documented at https://symfony.com/bundles/EasyAdminBundle/current/fields/TextEditorField.html#settrixeditorconfig

When I did so, I was able to create a heading in the Trix editor in EasyAdmin, and when viewing the saved field the heading was a correct h3 and the div tags were correctly replaced by p tags.

However, when I edited my entity again, Trix completely lost the heading tag and didn't show it in the editor. Re-saving the entity without making any changes incorrectly removed the headings.

To Reproduce

EasyAdmin version is 4.6. To reproduce, install EasyAdmin. In an entity CRUD controller, in the configureFields() function, define a field as follows:

yield TextEditorField::new('description')->setTrixEditorConfig([
    'blockAttributes' => [
        'default' => ['tagName' => 'p'],
        'heading1' => ['tagName' => 'h3'],
    ]
]);

Then edit your entity using that CRUD controller, set a heading within the field, save the entity, then edit it again - and notice that Trix has lost the heading.

Screenshots

First edit:
Screenshot 2023-04-22 at 13 59 38

View result (correct):
Screenshot 2023-04-22 at 14 00 17

Edit entity again (Trix loses the h3 heading):
Screenshot 2023-04-22 at 14 00 28

Save entity without making changes - h3 is lost:
Screenshot 2023-04-22 at 14 00 48

@ByNetherdude
Copy link

ByNetherdude commented Aug 6, 2023

Facing the same issue. Any updates?

@digitaltim-de
Copy link

Same Issue. I need a good editor that can i use for my blog.

@welcoMattic
Copy link
Contributor

welcoMattic commented Sep 18, 2023

I have the same issue. After digging in EA persistence process, I figured out that the correct value is saved in database. However, when re-editing the content, this is here the custom tag is lost.

Once the form is rendered, we can see in HTML:

  • The textarea hidden, with the right content (and the custom tag)
  • The trix editor element, without the custom tag.

I guess it's because the configuration of Trix made by EA is done too late. It should listen on trix-before-initialize to customize the configuration.

Beside, we should find a way to easily allow the addition of custom tools to the sidebar (like h2, h3, etc). blockAttributes allow to define the type of new tools, but we miss the control on the toolbar markup (and be able to add new buttons).

https://github.com/basecamp/trix/tree/1.3.1#observing-editor-changes

javiereguiluz added a commit that referenced this issue Sep 18, 2023
This PR was merged into the 4.x branch.

Discussion
----------

fix(trix): fix trix editor config loading

Ref #5725

This PR change the listen event to boot TextEditorField. Before it listen on `DOMLoadedContent`. Now it listen on `trix-before-initialize` to be sure to handle the custom configuration and render properly a `heading1` element with a custom tagName `h2` for example.

If needed, I can add some tests to cover it.

Commits
-------

1f49189 fix(trix): fix trix editor config loading
@javiereguiluz
Copy link
Collaborator

Fixed in #5928.

Thanks a lot for reporting this error and for fully investigating its cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants