BUGS - Cannot read property 'querySelector' of null at r.getBody
Question
Hi
I was trying to use grapesjs on visualsource pages.
Following is the init function -
`initEditor: function(){
var self = this;
this.editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '500px',
width: 'auto',
storageManager: false,
panels: { defaults: [] },
blockManager: {
appendTo: '#blocks',
blocks: self.wcComponents
},
});
this.editor.runCommand('sw-visibility');
this.editor.Panels.addPanel({
id: 'basic-actions',
el: '#canvas-panel',
buttons: [
{
id: 'export',
className: 'btn-open-export slds-button slds-button_brand',
label: 'Export To HTML',
command: 'export-template',
context: 'export-template', // For grouping context of buttons from the same panel
}, {
id: 'show-json',
className: 'btn-show-json slds-button slds-button_brand',
label: 'Export To JSON',
context: 'show-json',
command(editor) {
editor.Modal.setTitle('Components JSON')
.setContent(`<textarea style="width:100%; height: 250px;">
${JSON.stringify(editor.getComponents())}
</textarea>`)
.open();
},
},
{
id: 'show-css',
className: 'btn-show-json slds-button slds-button_brand',
label: 'Export CSS',
context: 'show-css',
command(editor) {
editor.Modal.setTitle('Editor CSS')
.setContent(`<textarea style="width:100%; height: 250px;">
${JSON.stringify(editor.getCss())}
</textarea>`)
.open();
},
},
{
id: 'show-preview',
className: 'btn-show-json slds-button slds-button_brand',
label: 'Preview',
context: 'show-css',
command: 'core:preview',
}
],
});
//newElement: {wcId: "", TagName: "", TagType: "", OnEvent: {}, Properties: {classes: [], Attributes: [], Style: []} };,
this.editor.on('component:add', (element, argument) => {
console.log("component:add", element, argument);
var id = element.ccid;
element.attributes.attributes['data-wcId'] = id;
self.newElement.TagName = element.attributes.tagName;
self.newElement.wcId = id;
self.newElement.Properties.Attributes = element.attributes.attributes;
for(var i=0; i < element.attributes.classes.models.length; i++){
self.newElement.Properties.classes.push(element.attributes.classes.models[i].attributes.name);
}
self.builderElements.push(self.newElement);
self.resetnewElement();
})
this.editor.on('component:remove', (some, argument) => {
console.log("component:remove", some, argument);
})
this.editor.on('component:selected', (selectedComponent, argument) => {
selectedCopmMetadata = {};
self.selectedComp = selectedComponent;
self.showPropertyTab();
console.log("component:selected", selectedComponent, argument);
_.each(selectedComponent.getAttributes(), function(value, key){
console.log(value, key);
if(key == "data-wcId"){
self.selectedCopmMetadata = _.findWhere(self.builderElements, {wcId : value});
console.log(self.selectedCopmMetadata);
}
//self.selectedCopmMetadata.setClass('slds-input test');
})
})
this.editor.on('block:drag:start', (dropBlock, argument) => {
console.log("block drag start");
//console.log(self.editor.Canvas.getElement());
})
},`
This function adds grapes page builder perfectly but get following error in console.
Answers (2)
Create a reproducible demo please
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #998
[BUG] Asset Manager sends empty request when uploading image
Description: GrapesJS editor is initialized in an editor.html file as follows: localhost:9001 is a local IIS server running PHP5. The conte...
Issue #974
[Question] Removing the deviceManager and ViewCode buttons
I'm playing with the default init to try and remove the deviceManager and ViewCode buttons... var editor = grapesjs.init({ showOffsets: 1,...
Issue #507
uploadFile being called twice on drop file?
I have an editor initialized as so: If I add an image to the canvas and try to upload a new image by dragging it into the drop area in the...
Issue #1288
Cannot read property 'body' of null - Angular
Hi, I have a list of email template (page 'templates') and there is a button that open the edit (page 'templates/edit/:templateId'. All wor...
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.