RenderField in traitView does not handle null or undefined
Question
Hi @artf!
Working on the editor on one of my custom traits i had an issue where for some reason that is not important, the createInput was returning undefined.
I've noticed that the TraitView renderField method does not handle falsey values
renderField() {
const { $el, appendInput, model } = this;
const inputs = $el.find('[data-input]');
const el = inputs[inputs.length - 1];
let tpl = model.el;
if (!tpl) {
tpl = this.createInput
? this.createInput(this.getClbOpts())
: this.getInputEl();
}
if (isString(tpl)) {
el.innerHTML = tpl;
this.elInput = el.firstChild;
} else {
appendInput ? el.appendChild(tpl) : el.insertBefore(tpl, el.firstChild);
this.elInput = tpl;
}
model.el = this.elInput;
}
It when directly to try to append an undefined object, raising an error.
Should i add a validation here checking that the object is present or should i do it somewhere else? Should it be the responsibility of createInput to always return a defined object?
Thanks!
Answers (2)
Hi Juan, thanks for the report, yeah actually createInput requires you to return an HTML string or HTMLElement. I think it's good to have errors in cases like that but I guess the error wasn't clear enough.
Honestly, I don't know what is the best "fix" here, because checking statically in the code all the API is not a scalable solution
Hello @artf! Hope you are well. I am having an issue using grapesjs plugin publish s3.. How can i use that plugin and publish my data??
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1909
SetComponents is sometimes very slow
Hi all We're working on a newsletter app and are using grapesjs as the email editor with the newsletter preset plguin and some custom chang...
Issue #2337
[BUG / QUESTION] Deleting default styles does not work
Hello, i'm trying to delete some of the default styles of the blocks. I wrote everything I changed in a plugin. I used this function to upd...
Issue #2972
FEAT: Disable scripts on canvas
Hello, first of all thanks for a great tool. On my project i hit the problem where I need to disable scripts inside the editor. I found 2 s...
Issue #1516
ckeditor 5 [enhancement]
Hey @artf , as described in the following task I made a build of the ckeditor 5 which works with GrapesJS, however some of the functionalit...
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.