Skip to content

Commit

Permalink
- move 'editor' parameter to the last position
Browse files Browse the repository at this point in the history
- send standard array path instead of jsonpath in getOptions
  • Loading branch information
ianido committed Jul 7, 2017
1 parent d423a70 commit 495ed38
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ Constructs a new JSONEditor.

Indicate the KeyCodes for trigger confirm completion, by default those keys are: [39, 35, 9] which are the code for [right, end, tab]

- `{Function} getOptions (editor: object, text: string, path: string, input: string)`
- `{Function} getOptions (editor: object, text: string, path: string[], input: string)`

This function will return your possible options for create the autocomplete selection, you can control dynamically which options you want to display according to the current active editing node.

*Parameters:*
- `editor` : The editor instance object that the node belongs to.

- `text` : The text in the current node part. (basically the text that the user is editing)
- `path` : The json path of the node that is being edited.
- `path` : The path of the node that is being edited.
- `input` : Can be "field" or "value" depending if the user is editing a field name or a value of a node.
- `editor` : The editor instance object that the node belongs to.

*Returns:*

Expand Down
2 changes: 1 addition & 1 deletion examples/12_autocomplete_dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
modes: ['text', 'tree'],
autocomplete: {
applyTo:['value'],
getOptions: function (editor, text) {
getOptions: function (text, path, input, editor) {
return new Promise(function (resolve, reject) {
var options = extractUniqueWords(editor.get());
if (options.length > 0) resolve(options); else reject();
Expand Down
2 changes: 1 addition & 1 deletion examples/13_autocomplete_advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
autocomplete: {
confirmKeys: [39, 35, 9, 190], // Confirm Autocomplete Keys: [right, end, tab, '.'] // By default are only [right, end, tab]

getOptions: function (editor, text, path, input) {
getOptions: function (text, path, input, editor) {
if (!text.startsWith(activationChar) || input !== 'value') return [];
var data = {};
var startFrom = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/js/treemode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ treemode._onKeyDown = function (event) {
// Activate autocomplete
setTimeout(function (hnode, element) {
if (element.innerText.length > 0) {
var result = this.options.autocomplete.getOptions(hnode.editor, element.innerText, hnode.getNodeJsonPath(), jsonElementType);
var result = this.options.autocomplete.getOptions(element.innerText, hnode.getPath(), jsonElementType, hnode.editor);
if (typeof result.then === 'function') {
// probably a promise
if (result.then(function (obj) {
Expand Down

0 comments on commit 495ed38

Please sign in to comment.