Issue #3638Opened July 23, 2021by momu-20160 reactions

BUG: script-props is invalid

Question

Hi!@artf,Thanks for your great work! I follow the https://grapesjs.com/docs/modules/Components-js.html#passing-properties-to-scripts,but when i select the value,The script was not executed,Looking forward to some suggestions,thank you so much!

export default function (editor, opt = {}) {
  const c = opt;
  const domc = editor.DomComponents;
  const defaultType = domc.getType("default");
  const defaultView = defaultType.view;
  const TYPE = "test";
  const script = function (props) {
    alert("Hi");
  };
  editor.Components.addType(TYPE, {
    model: {
      defaults: {
        script,
        stitle: "value1",
        'script-props': ['stitle'],
        traits: [
          {
            type: "select",
            name: "stitle",
            changeProp: true,
            options: [
              { value: "value1", name: "Value 1" },
              { value: "value2", name: "Value 2" },
            ],
          },
        ],
      },
      Component(el) {
        if (el.getAttribute && el.getAttribute("data-gjs-type") == TYPE) {
          return {
            type: TYPE,
          };
        }
      },
    },
    view: defaultView.extend({}),
  });
}
```

`

Answers (1)

artfJuly 29, 20210 reactions

Seems to work all properly here: https://jsfiddle.net/rp7wa58h/ Anyway, you don't need the view if you don't use it, and the same for isComponent (which is misspelled in your example and placed in the wrong place), data-gjs-type is already used, by default, in the same way automatically by the editor

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.