Issue #1771Opened January 31, 2019by Soharab-Shaikh1 reactions

Traits type : button not working

Question

Hi, @artf When I try to use button type traits. It does not fire any function. Can you please help me with this. Can you please share an example of new traits type creation like "Button", not the "Content" one.

Code SnippetTEXT
`traits: [
	{
	type: 'button',
	label: 'Submit',
	name: 'blog_submit',
	changeProp: 1
	}
]
....													
init() 
{
	this.listenTo(this, 'change:blog_submit', this.changeFilter);
}
.....`


**For new traits type creation, I am trying**

 editor.TraitManager.addType('button', {
       events: {
            **'keyup' : 'onChange'**  **// what should we use in this part?**
        },
        getInputEl: function () {
            if (!this.inputEl) {
                var x = document.createElement("INPUT");
                x.setAttribute("type", "button");
              // x.setAttribute("onclick", "changeData()");
                this.inputEl = x;
            }
            return this.inputEl;
        }
      //changeData: function () {
       //alert("hi");
     // }
    });

Answers (2)

artfFebruary 6, 20191 reactions

Hi @Soharab-Shaikh you have to pass the command option (will be executed on click):

traits: [
	{
		...
		type: 'button',
		command: 'COMMAND-ID',
		// or like a function
		command: editor => {
			const selected = editor.getSelected();
			// do something...
		},
	}
]
lock[bot]February 7, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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.