Change an element type in editor
Question
Hi,
In my javascript i already create 2 components (type "A" and type "B) with their own traits. I create a context menu on both elements to switch (in the editor) the selected element from type "A" to type "B" and change the traits in consequence.
I didn't found the way to change the type of an element already insert in the editor. Do you have a function or a solution plz?
Thanks artf !
Answers (3)
Take a look here: https://grapesjs.com/docs/modules/Traits.html#add-traits-to-components
It shows how to add/remove custom traits for existing types. It may help you
Thanks, but i don't want to change the type but i want to change the type of only one selected element... If i change the traits of component, all the others elements with this type will be changed and it's not the purpose.
I didn't found the way to change the type of an element already insert in the editor.
The solution will be the same in case you would like to change a <div> with an <img>... so you remove it and replace it with another component at the same index
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1930
[QUESTIONS] change 2 attributes with 1 trait
I have an input trait, I want to change the 2 attributes (name and type) on the selected input element, on canvas is appropriate, but in th...
Issue #1044
change src for image element in model
hello when a image block drop to editor i hide the default asset manager and display my custom asset manager: fot this i have no problem.bu...
Issue #1047
[BUG] Model not able to change after changing value in custom Select dropdown menu.
Hey, I'm using CDN link for grapes js from unpkg.com In my project, I've used custom trait as a drop-down select menu which changes HTML us...
Issue #1307
Question: To stop dynamically generated classes in grapes Editor
Hi @artf is there any Way to stop dynamically generating classes on reloading editor. let say when i add my custom class i.e "my_class" to...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.