Custom Traits not Updating if using mjml
Question
setTimeout(() => {
editor.DomComponents.addType("mj-image", {
isComponent: (el: any) => el.tagName === "MJ-IMAGE",
model: {
defaults: {
traits: [
{
type: "mjchange",
label: " ",
name: "mjchange",
},
{
type: "href",
label: "Link",
name: "href",
},
{
type: "alt",
label: "Alt",
name: "alt",
},
],
},
},
});
editor.TraitManager.addType("mjchange", {
noLabel: true,
createInput({}) {
let selectedSrc = editor.getSelected();
let src = selectedSrc!.attributes.attributes!.src;
const toggleModal = () => {
editor.runCommand("open-assets", {
target: editor.getSelected(),
});
};
const el = document.createElement("div");
el.setAttribute("class", "image-trait-preview");
el.innerHTML = `<img src="${src}" style="width: 100%; height:auto;background:#f9f9f9;" id="gjs_img_preview_logo_rtl"/>
<button type="submit" class="btn btn-primary btn-block btn-sm" id="chg-img-trait-btn">Change</button>`;
const inputType = el.querySelector("#chg-img-trait-btn");
const imgBox = el.querySelector("#gjs_img_preview_logo_rtl");
imgBox!.addEventListener("click", toggleModal);
inputType!.addEventListener("click", toggleModal);
return el;
},
});
editor.on("modal:open", (component) => {
const $ = editor.$;
editor.AssetManager.open({
types: ["mj-image"],
select(assets, complete) {
const selected = editor.getSelected();
if (selected && selected.is("mj-image")) {
selected.addAttributes({ src: assets.getSrc() });
$("#gjs_img_preview_logo_rtl").attr("src", assets.getSrc());
complete && editor.AssetManager.close();
}
},
});
This Method Works Fine for Normal HTML. But When I Tried With MJML For MJ-IMAGE Tag
The Src is Updated in TR Tag but not updated in img tag inside the TR tag
The Below Image

Originally posted by @RakulAgn in https://github.com/artf/grapesjs/discussions/4795
Answers (1)
@RakulAgn please avoid creating issues from discussions.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3233
Set Toolbar on every Component
Hi @artf Is there any standard way to add a new toolbar on every component I've tried this way When I run this code on the browser console...
Issue #2614
[QUESTION] Recursive view update of custom component
Hi, I have defined a custom type like: I want to keep the customTag in my model and show the content (HTML) in the view. However, in the co...
Issue #1724
[QUESTION] link custom traits to my custom blocks
Hi, i have created a custom traits and custom blocks but i try to link my blocks in traits, it does not shows in settings option my custom...
Issue #3228
Component Value is not changing
Hi @artf I've added a new component here is the code on selecting the h1 and h2 tag it's changing the value in the HTML section as you can...
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.