Traits
Hi Freddy, you can simply extend the image component in this case
Read full answer below βQuestion
Hi @artf - what you've built is magnificent. It's been a gentle struggle as I'm far from being a JS wizard. However, I've got just about everything fully configured - except for this! I want to set traits that display when an image is selected (alt, src, id). I am sure it can be done once at initialisation, but I'm buggered if I can figure out how do do it. I've read everything I can find in the issues and am still stuck. The only way I got it to work is as follows ... Also - the out-of-the-box "Alt" comes first and I'd really like it to be after . I can't figure out how to get rid of it as d...
Answers (2)
Hi Freddy, you can simply extend the image component in this case
editor.Components.addType('image', {
model: {
defaults: {
traits: [{name: 'alt'}, {name: 'src'}, {name: 'id'}]
}
}
});
Thanks for reporting this, @fmay. Great question about Question : Traits. The recommended approach with Components is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Most operations can be achieved by listeni...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6040
Cannot read properties of undefined (reading 'lastComponent')
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Version 127.0.6533.89 (Official Build) (64...
Issue #5263
Deleting a component without deleting its corresponding style, will adding new components later cause style conflicts?
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? latest version of Chrome Reproducible demo...
Issue #3778
Select options are not displaying - new anomaly
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? ChromeReproducible demo link https://github....
Issue #3731
Text element not able to be selected twice after extended with events
Version: 0.17.25 Are you able to reproduce the bug from the demo?[ ] Yes[x] No What is the expected behavior? Update a existing component o...
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.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins β TinyMCE Inline Text Editor and Placeholder.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.