GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.37k stars 4.05k forks source link

RenderField in traitView does not handle null or undefined #3265

Closed jcamejo closed 1 year ago

jcamejo commented 3 years ago

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!

artf commented 3 years ago

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

WebDevXpert commented 3 years ago

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