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

Traits type : button not working

Quick answerby artf1

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

Read full answer below ↓

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: 'blogsubmit', changeProp: 1 } ] .... init() { this.listenTo(this, 'change:blogsubmit', 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.create...

Answers (2)

artfFebruary 6, 2019

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, 2020

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

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.