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)
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.
Issue #2069
[BUG] `allowScripts: true` still deletes <script> tags
Hi all. Thanks for creating and maintaining this amazing project. 🙏 Bug Description I have a block that inserts a script as specified here...
Issue #1894
[BUG] Custom Trait documentation example doesn't work
Specifically this: https://grapesjs.com/docs/modules/Traits.html#define-new-trait-type First of all, the keyUp event references onChange wh...
Issue #1569
Components & JS Question
Hi, In your Components & JS documentation, it is mentioned that scripts can be added into the "block" section under a script attribute. How...
Issue #4765
BUG: The documented way to parse @keyframes does not work
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome v107Describe the bug How to reproduce...
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.