From 495ed3806386ab96c80c98bb6810c06bbc7d7b36 Mon Sep 17 00:00:00 2001 From: Israel Garcia Date: Fri, 7 Jul 2017 13:43:15 -0400 Subject: [PATCH] - move 'editor' parameter to the last position - send standard array path instead of jsonpath in getOptions --- docs/api.md | 7 ++++--- examples/12_autocomplete_dynamic.html | 2 +- examples/13_autocomplete_advanced.html | 2 +- src/js/treemode.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/api.md b/docs/api.md index c01b39f..d1dc2e8 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 8dbd2ed..3c49b9c 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 28793d2..3a368cd 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 68632ce..40d193d 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) {