jodit icon indicating copy to clipboard operation
jodit copied to clipboard

dropdown list to insert text in editor

Open paulgodard opened this issue 4 years ago • 3 comments

I have created these 2 buttons to insert some text into the editor... that is working 100%. I need to add more buttons and instead of having an icon for each of them, i would like to place them in a dropdown list. How can I achieve that?

var editor = new Jodit('#editor', {
    buttons: [ 
        {   
            iconURL: '/public/icons/image_left.png',
            exec: function (editor) {
                editor.selection.insertHTML('...');
            }
        },
        {   
            iconURL: '/public/icons/image_right.png',
            exec: function (editor) {
                editor.selection.insertHTML('...');
            }
    }]
});

paulgodard avatar Jul 27 '21 09:07 paulgodard

var editor = new Jodit('#editor', { 
   buttons: [
       iconURL: '/public/icons/image_left.png',
       list: {
         first: 'first',
         second: 'second'
       },
        childTemplate: (editor, key: string, value: string) => {
		return `<span>${key}</span>`;
	}
        exec: function (editor, t, {control}) {
            editor.selection.insertHTML(control.args);
        }
   ]
});

xdan avatar Aug 03 '21 14:08 xdan

Thank you!

paulgodard avatar Aug 03 '21 21:08 paulgodard

        exec: function (editor, t, {control}) {
            editor.selection.insertHTML(control.args);
        }

Thanks! I was struggling with this.

The documentation at https://xdsoft.net/jodit/pro/docs/how-to/add-custom-button.md#drop-down-list seems to be incorrect. In the example there:

	exec(editor) { 
		let value = control.args && control.args[0]; // h1, h2 ...

control isn't received as an argument, therefore it's undefined here, and this line raises an error!

dgoldm avatar Jan 27 '22 18:01 dgoldm