Migrating From jQuery to Vanilla Javascript Discussion
It would be great to have a similar video covering how to add a toolbar button with a dialog so we can add things like a better link selector that chooses pages on our site. Or an image selection dialog.
Is it possible to add attributes to an attachment that we can get at when rendering the attachment? things like text (for links) and classnames etc. These would stay same if model data changes.
Can we set the class of the figure element for an attachment in the editor? If not it has attachment-content and is always inline. which looks a bit poor for things like media embeds
I'm having trouble with saving mentions in the controller. When I do post_params
I get
#<ActionController::Parameters {"body"=>"<div><figure data-trix-attachment=\"{"content":"<span class=\\"mention\\">\\n Jon Doe\\n</span>\\n"}\" data-trix-content-type=\"undefined\" class=\"attachment attachment--content\"><span class=\"mention\">\r\n John Doe\r\n</span>\r\n<figcaption class=\"attachment__caption\"></figcaption></figure> is awesome</div>"} permitted: true>
Then I create the post Post.create kudo_params
. And when I do Post.last.body
I get
"<div class=\"trix-content\">\n <div> is awesome</div>\n</div>\n"
Where has the mention gone?, it disappeared and survived just the text. The whole text was @John Doe is awesome
. Any help is welcomed!
Update: the problem was a typo in app/views/users/_user.json.jbuilder
, instead of defining sgid
I wrote sgsid
I referenced this screencast on this Trix Github issue where comments disappear if the user mentioned is a link and is clicked. Required a data turbo false tag to be filtered from trix content divs as well as allowing the data turbo false html content to be an allowed_attributes of action text.