Issue #931Opened March 7, 2018by altemberg0 reactions

[Question] Problems saving to DB

Question

Hi,

I'm having some problems saving the template in the database and I'm not exactly sure why this is happening.

I've read all the issues here and still can not save, there are always 3 things: Save it blank, save the array value or save a JSON with tens of bars between each value.

My code looks like this:

var editor  = grapesjs.init({
...
storageManager: {
    type: 'remote',
    stepsBeforeSave: 10,
    autosave: false,
    urlStore: "http://domain.com/api/save",
    urlLoad: "http://domain.com/api/load",
    contentTypeJson: true,
  },
});

editor.Panels.addButton('options',
  [{
    id: 'save-db',
    className: 'fa fa-floppy-o',
    command: 'save-db',
    attributes: {title: 'Save DB'}
  }]
);

editor.Commands.add('save-db', {
  run: function(editor, sender){
    sender && sender.set('active',0);
    editor.store();
    editor.on('storage:load', function(e) {
      console.log('Loaded ', e);
    });
    editor.on('storage:store', function(e) {
      console.log('Stored ', e);
    });
  }
});

// I have also tried this and some other ways
// editor.Commands.add('save-db', {
//   run: function(editor, sender){
//     sender && sender.set('active',0);
//     const RemoteStorage = editor.StorageManager.get('remote');
//     RemoteStorage.set('params', {
//       code: editor.store()
//       // other parameters
//     });
//     editor.store();
//     editor.on('storage:load', function(e) {
//       console.log('Loaded ', e);
//     });
//     editor.on('storage:store', function(e) {
//       console.log('Stored ', e);
//     });
//   }

});

When it is saved that way it returns on the console, I believe everything is correct and I have some problem just saving the codes, because I inserted some parameters and I can save them in the DB without any problem. console.log storage:store Printscreen

Answers (2)

artfMarch 8, 20180 reactions

Seems like the image you posted is corrupted. BTW, just look what does it happen at the network level (via inspector) and I'm sure you will find the error

One more thing, I know that you copied this from some other issue but here you're adding listeners on any new run of the command

editor.Commands.add('save-db', {
  run: function(editor, sender){
    sender && sender.set('active',0);
    editor.store();

	// Put them outside
    editor.on('storage:load', function(e) {
      console.log('Loaded ', e);
    });
    editor.on('storage:store', function(e) {
      console.log('Stored ', e);
    });
  }
});

lock[bot]September 18, 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.