Issue #625Opened December 10, 2017by Caimilan2 reactions

editor.store(); fires multiple times

Question

Hi @all, I use my custom code to stop data to server. All works fine, but editor.store(); fires once on first click, twice on second click, three times on third click ... and so on.

var editor = grapesjs.init({
	height: '100%',
	storageManager:{
		autosave: false,
		autoload: false,
		setStepsBeforeSave: 0,
		type: 'remote',
		contentTypeJson: false,
	},
.....

// save to server
cmdm.add('save-db',{
	run: function(editor, sender){
		sender && sender.set('active');
		editor.store();
		editor.on('storage:store', function(e) {
			console.log('Stored ', e);
			console.log(editor.runCommand('gjs-get-inlined-html'));
			var data = e;
			var inline = editor.runCommand('gjs-get-inlined-html');
			$.post(
				URLAPP + 'lib/editor-nl/save-tpl.php',
				{
					'data': data,
					'inlined': inline,
					'tpl-name': $('#panel-tpl-title').val()
				}
			);
		});
	}
});
pnm.addButton('options', {
	id: 'save-db',
	className: 'fa fa-floppy-o',
	command: 'save-db',
	attributes: {
		'title': 'Template speichern',
		'data-tooltip-pos': 'bottom',
	}
});

In storageManager -> type I use 'remote' - if use 'local' , fist click takes no effect. Can anyone help?

Answers (3)

artfDecember 10, 20172 reactions

Every time you call save-db

cmdm.add('save-db',{
	run: function(editor, sender){
   ...

you attach a new listener

editor.on('storage:store', function(e) { ...

pull it out from your command

shareefhiasatMay 15, 20180 reactions

do it like this so we dont attach listeners every time

editor.on('storage:load', function(e) {
        console.log('Loaded ', e);
    });

    editor.on('storage:store', function(e) {
        console.log('Stored ', e);
    });

    cmdm.add('save-db', {
      run: function(editor, sender)
      {
            sender && sender.set('active'); // turn off the button
            editor.store();
      }
    });
lock[bot]September 17, 20190 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.