josdejong / josdejong/jsoneditor

Custom insert with onCreateMenu

Open
#1,361 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
12.3k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

I've been struggling with how to use the onCreateMenu function to auto populate valid values that I would like to insert into the json. I realize I would use editor.update(), but I basically want the functionality the same as insert with my custom key/type pair.

This would allow me to restrict valid values to the predefined context menu submenu items.

Here is my current function, and I think this is pretty clear what i'm trying to do. Any tips/tricks that I may be missing?

```
onCreateMenu = (items, node) => {
debugger;
const submenu = this.state.keywords.map((keyword: Keyword) => {
return {
type: "append", // doesn't affect callback
text: keyword.keyword,
title: keyword.title,
className: "not-used-right-now",
click: _.bind(function (a, b, c, d) { // all these values are undefined
debugger
node._onAppend(`keyword.keyword`, {});
}, this),
};
});

items.push({
type: "append",
text: "Cubby Values",
title: "Show the possible valid keywords for this property",
className: "no-used-right-now",
submenu,
});

//debugger;

return items;
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.