Adding / Updating href trait does not add `<a></a>` wrapper to image.
Question
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"><img src="/></a>
Current behavior = no change is reflected
Here's code for adding trait
function updateTrait(model){
const selectedElement = model.model
.parent()
.components()
.models.filter(
(m) =>
m.attributes?.tagName === "mj-image" &&
m.ccid === model.model.getId()
)
.slice(-1)[0];
selectedElement.getTrait('href').set('value', 'google.com');
}
```
The above function is triggered on double click,
```
dc.addType('mj-image', {
onActive(ev) {
ev && ev.stopPropagation();
openModal(this);
},
events: {
dblclick: "onActive",
},
}
)
```
Please help me how do I add href to image dynamically from code without using trait manager.
```
Answers (3)
It's not working, even if I do `selectedElement.getTrait('href').set({value: 'fb.com', target: '_blank'})
I think the component view is not getting updated, if I repeat the action, it is rendering a tag with previous value.
It works if I update href in the attributes
Related Questions and Answers
Continue research with similar issue discussions.
Issue #418
Can't replace image if it's inside a link
Hi, If import this code inside the editor: And double click the image to change it, when I choose a new image from the modal, nothing happe...
Issue #3009
BUG: Restricting Drop on Wrapper Component
Version: 0.16.22 Are you able to reproduce the bug from the demo? [ ] Yes [ X] No - requires editing js. What is the expected behavior? wra...
Issue #3237
Add Trait For wrapper
Hi @artf I've added trait for wrapper this way. How can I perform the init function for the same Here is the code @artf Could you please he...
Issue #2849
[BUG] Using image url for background-image is not working properly
DescriptionOn our project for images assets we use url instead of base64 code .Expected behavior When setting a background-image to a contr...
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.