[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.
Answers (2)
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);
});
}
});
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 #1908
[question] Cannot read property 'indexOf' of undefined
I found a previous result here: https://github.com/artf/grapesjs/issues/1772 however I can still not get it to work, using the most basic s...
Issue #1682
Remove cookies on GrapesJS?
Hello! I'm using the latest version of GrapesJS, however it is causing issues with my project, because GrapesJS is saving the edits as a co...
Issue #822
[QUESTION] How to get the html and css code in view code tool?
or how to get all the html code and css so that I could save it in my database. Or there is already a functionality in the documentation? y...
Issue #841
[QUESTION] Add default Trait (attribute) to model for all HTML Components (elements)
Hi, I've read the Traits, Components and API wikis, grepped all the open & closed issues. I've even found the code where you are creating t...
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.