Issue #625✓ SolvedOpened December 10, 2017by Caimilan2 reactions

Editor.store(); fires multiple times

快速解答by artf2

Every time you call save-db you attach a new listener pull it out from your command

Read full answer below ↓

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)

👍 Most helpfulartfDecember 10, 2017

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

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

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.