diff --git a/docs/api.md b/docs/api.md index c01b39fe0..d1dc2e820 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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:* diff --git a/examples/12_autocomplete_dynamic.html b/examples/12_autocomplete_dynamic.html index 8dbd2ed03..3c49b9c46 100644 --- a/examples/12_autocomplete_dynamic.html +++ b/examples/12_autocomplete_dynamic.html @@ -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(); diff --git a/examples/13_autocomplete_advanced.html b/examples/13_autocomplete_advanced.html index 28793d253..3a368cd49 100644 --- a/examples/13_autocomplete_advanced.html +++ b/examples/13_autocomplete_advanced.html @@ -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; diff --git a/src/js/treemode.js b/src/js/treemode.js index 68632cede..40d193de1 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -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) {