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.
`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)
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...
},
}
]
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.
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
Issue #558
Help: Can you please give an example of Chart.js as a block in grapesjs.
@artf can you please give one complete example of a chart using chart.js with traits for changing the colour, values & Data Points.? It wou...
Issue #1998
Extending Link component not working properly.
hello @hello @artf I am trying to extend the link component and add new traits like href and target the code is given below. `function load...
Issue #1720
[QUESTION] How to add the button in custom traits
Hi, I try to add a button to my custom traits for my custom blocks but its not working fine as expected and also need to know how to call t...
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.