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)
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
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();
}
});
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 #1756
Drag and Drop not working in resized editor window in Google Chrome
Hi, I developed some components and all works fine in Firefox, Opera browser. In Google chrome also working fine in fullscreen editor mode...
Issue #1127
Command running multiple times
Hello Folks, I need your help.I created a custom button on the commands Panel to publish the site created from Grapes.When i click on it, i...
Issue #743
editor.getComponents() load multiple times when refreshed.
Hello, editor.getComponents().add('<div class="grid-stack" style="height:800px;"></div>'); adds multiple times when refreshed, how stop thi...
Issue #1150
[Question] Get Uploads as Base64
Hello All, I need help integrating this into a web app that I have. Everything renders and works as expected but I am trying to get the upl...
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.