From 088d7d6c90bc1214c06307832ef22d4be4846870 Mon Sep 17 00:00:00 2001 From: Israel Garcia Date: Thu, 29 Jun 2017 01:57:54 -0400 Subject: [PATCH] - Change signature of getOptions function to (text, path, input) - Remove node object from exposure. - Improve startFrom option by returning the start position. --- docs/api.md | 11 ++----- examples/12_autocomplete_dynamic.html | 9 ++---- examples/13_autocomplete_advanced.html | 21 ++++++------- examples/jsonpath.min.js | 20 ++++++++++++ src/js/autocomplete.js | 3 +- src/js/treemode.js | 43 ++++++++++++++------------ 6 files changed, 61 insertions(+), 46 deletions(-) create mode 100644 examples/jsonpath.min.js diff --git a/docs/api.md b/docs/api.md index 3c5986d..5e54ddb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -157,10 +157,6 @@ 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] - - `{Object} applyTo` - - Indicate where the autocomplete is going to be activated, under field in json node or/and under value in a json node, default is: ['field','value'] - - `{Function} getOptions (autocomplete, node, text, elementType)` 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. @@ -168,10 +164,9 @@ Constructs a new JSONEditor. *Parameters:* - - autocomplete : The instance of the autocomplete engine. - - node : The current active editing node. (node include field and value) - - text : The text in the current node part. (basically the text that the user is editing) - - elementType : Can be "field" or "value" depending if the user is editing a field name or a value of a node. + - text : The text in the current node part. (basically the text that the user is editing) + - path : The document json object 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. ### Methods diff --git a/examples/12_autocomplete_dynamic.html b/examples/12_autocomplete_dynamic.html index 1b49970..6f4df1e 100644 --- a/examples/12_autocomplete_dynamic.html +++ b/examples/12_autocomplete_dynamic.html @@ -38,17 +38,14 @@ modes: ['text', 'tree'], autocomplete: { applyTo:['value'], - getOptions: function (autocomplete, node, text) { + getOptions: function (text, path) { return new Promise(function (resolve, reject) { - var data = node.editor.get(); - var options = extractUniqueWords(data); + var options = extractUniqueWords(path); if (options.length > 0) resolve(options); else reject(); }); } } - }; - - + }; // ... diff --git a/examples/13_autocomplete_advanced.html b/examples/13_autocomplete_advanced.html index 2b9cc63..d5e32c5 100644 --- a/examples/13_autocomplete_advanced.html +++ b/examples/13_autocomplete_advanced.html @@ -5,6 +5,7 @@ +