Trying to add onClick attribute to component
Question
Hello,
Fairly new to this great project but I am trying to change the display of a component onClick of another component after the component id is selected from the dropMenu. I'm having trouble trying to add an onClick attribute to the component after selection from a dropMenu trait. I can't seem to access the value of the dropMenu trait from within addAttributes(). I also can't use any variable from outside addAttributes() such as `var comp = document.getElementById(this.get("traits").where({name: "dropMenu"})[0].get("value"))` including editor.getSelected().
Thanks in advance
` editor.Components.addType('link', {
isComponent: (el: any) => {if (el.tagName === 'a'){
return {type: 'link'}
}},
model: dModel.extend({
init() {
this.listenTo(this, 'change:attributes:dropMenu', () => {
this.addAttributes({'onClick': 'document.getElementById(this.get("traits").where({name: "dropMenu"})[0].get("value")).style.display="block"'})
})
},
defaults: Object.assign({}, dModel.prototype.defaults,{
traits: ['title', 'href', 'target',{type: 'dropMenu', name: 'dropMenu'} ]
],
}),
})
});
}`Answers (0)
No answers yet.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1113
[QUESTIONS] New trait type is not working with rendered components?
Hello, thanks for the great framework. I'm trying to apply this to my project. I want to add a new trait for existing LINK '<a>' component....
Issue #2961
BUG: Components in custom modal isn't editable
Hello, I'm trying to add custom modal block to my project and I want to change content of this modal also with drag&drop. Here's code of my...
Issue #1982
[QUESTIONS] addcomponent after the selected component
how do I make it possible to add new components after the component I selected, at this time I use editor.DomComponents.addComponent (block...
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...
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.