Issue #3265Opened February 5, 2021by jcamejo0 reactions

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)

artfFebruary 19, 20210 reactions

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

WebDevXpertOctober 7, 20210 reactions

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.

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.