Issue #3171Opened December 7, 2020by skbhagat400 reactions

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)

skbhagat40December 7, 20200 reactions

It's not working, even if I do `selectedElement.getTrait('href').set({value: 'fb.com', target: '_blank'})

skbhagat40December 8, 20200 reactions

I think the component view is not getting updated, if I repeat the action, it is rendering a tag with previous value.

skbhagat40December 9, 20200 reactions

It works if I update href in the attributes

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.