Adding extra attributes with Stylemanager to change selected block's attribute
@Ace0611 you can use traits for both controlling props (id, title & etc) and attributes. Cheers!
Read full answer below ↓Question
Thanks for this awesome plugin. I am integrating it with my current project. Have one issue with it. Here is my code, I have added a new sector with 3 input fields, I want to change the selected block's attribute(id, readOnly) with my value in those input fields. for instance: I want to change id of the selected block with my functionality. How can i achieve this?
editor.StyleManager.addSector( "mySector",
{
name: "Element Attributes",
open: true,
properties: [{ name: "id" }, { name: "name" }, { name: "readOnly" }]
// buildProps: ['id', 'readOnly'],
},
{ at: 0 }
);
and to change the attribute of selected component:
editor.on("block:drag:stop", function(droppedComponent) {
droppedComponent.addAttributes({
id: "customId"(it should take it from the input)
// onclick: `jsFunc('#${randomId}')`
});
});Answers (3)
@Ace0611 you can use traits for both controlling props (id, title & etc) and attributes. Cheers!
@Ace0611
Will using id by traits override that?
yes! id is just a regular prop like others. And notice that grapesjs already provides you with default traits for id & title.
Cheers!
@pouyamiralayi : Thanks for helping me out. One doubt though, Every block that is being dragged, generates a dynamic id. Will using id by traits override that? My apologies, I am travelling right now, so cant do it myself at the moment. I will try it as soon as possible.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1951
[QUESTIONS] change or add event on add component from block
is it possible ?, change the drag and drop event to on click when adding a new component, I want to add components by clicking the block th...
Issue #701
Modifying a component in the editor clears the model content
What I'm trying to achieve: I have special "data-" attributes on some of the components I pull into the editor. When one of these is modifi...
Issue #3171
Adding / Updating href trait does not add `<a></a>` wrapper to image.
Expected Behavior - when I update href trait value, the image should be wrapped inside a with href value set. i.e. <a href="google.com"><im...
Issue #2089
How to reload block content based on trait value change
I have added new block with some trait value and i want to pass that trait value with ajax call. Also should be able to reload block when t...
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
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
GrapesJS vs Webflow vs Builder.io vs Puck: Which Visual Builder to Choose in 2026
A practitioner's 2026 comparison of GrapesJS, Webflow, Builder.io, and Puck — pricing, AI features, lock-in, and a one-line rule for picking the right one
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.