Add custom attributes (data-) to assets/images on Upload/Selection
Found a solution, but surely there is a better one than this: Thanks.
Read full answer below āQuestion
Hi, I am trying my best to find the proper/best way to do this, but I need to attach two custom HTML5 data tags to an image once it is selected from the Assets manager. Like so: I was hoping to be able to attach it when adding assets. Since I couldn't get that to work, I tried adding them on the component update event, but doubt that is returning a value to update them after being added. So next I tried using the selector and jQuery to add the attributes on the component update event, but that did not work either. I also tried extending the image component, and selecting that via the add asse...
Answers (3)
Found a solution, but surely there is a better one than this: Thanks.
Your solution only updates the element inside the canvas and not its model (so in your final code you'll not gonna see them). When you update the model its element in view is updated automatically, eg.
Thanks! Would there be a feature in the future to add attributes during asset import? Just curious.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1702
[Question]How to get rte selection inside the result function
I'm basically trying to put an input fieldinside the RTE so that users can make link more easily. console.log(<a href="#">${rte.selection()...
Issue #1578
[Question] Custom request on "src" attributes
I implemented a small GrapesJS editor that allows to edit Django/Jinja2 templates. GrapesJS by default is trying to GET the image preview o...
Issue #372
Asset Manager not automatically add images to assets after uploading
The JSON response of an upload is like this {"data":["http://url.com/flower.jpg"]} The response event is working.In the response event resp...
Issue #930
[Question] Update resizer after asset changed
Hi! I trying to change default assets manager with ours custom manager. On double click the selected image is replaced with a new one with...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins āPremium plugins ship with support, regular updates, and production-ready features ā save days of integration work.
Browse premium plugins āRelated tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.