grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

RenderField in traitView does not handle null or undefined

Open jcamejo opened this issue 4 years ago • 2 comments

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!

jcamejo avatar Feb 05 '21 14:02 jcamejo

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

artf avatar Feb 19 '21 19:02 artf

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??

WebDevXpert avatar Oct 07 '21 08:10 WebDevXpert