Issue #3529Opened June 10, 2021by tmrowe1230 reactions

Trying to add onClick attribute to component

Question

Code SnippetTEXT
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.

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.