aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsp00n <sp.00.n@gmx.net>2021-05-20 22:55:02 +0200
committerGitHub <noreply@github.com>2021-05-20 22:55:02 +0200
commit32bcb0326a097d37196ad689e8222c1c5e41c7b5 (patch)
tree0205f6244a1fbe3252801c155753cf13d7c59093
parentfb30170bc138ee2ec609927150ca8c33c378400d (diff)
Update README.md
-rw-r--r--README.md38
1 files changed, 35 insertions, 3 deletions
diff --git a/README.md b/README.md
index fa67f9b..d5f704d 100644
--- a/README.md
+++ b/README.md
@@ -21,12 +21,37 @@ ac.setData([
]);
```
+
+Or use custom label/value keys:
+```js
+const ac = new Autocomplete(field, {
+ data: [{name: "entry1", text: "The first entry"}, {name: "entry2", text: "The second entry"}],
+ label: "name",
+ value: "text",
+ onSelectItem: ({label, value}) => {
+ console.log("user selected:", label, value);
+ }
+});
+```
+
+Or use a simple object instead of an array of objects:
+```js
+const ac = new Autocomplete(field, {
+ data: {entry1: "The first entry", entry2: "The second entry"},
+ label: null,
+ value: null,
+ onSelectItem: ({label, value}) => {
+ console.log("user selected:", label, value);
+ }
+});
+```
+
### Options
Options is a JSON object with the following attributes (in alphabetical order):
**data**:
-The data from where autocomplete will lookup items to show. This data has to be an array of JSON objects. The format for every item in the array is:
+The data from where autocomplete will lookup items to show. This data can be a simple object or an array of JSON objects. By default the format for every object in the array is as following, but you can also change the name of the label and value keys (see below):
{"label": "This is a text", "value": 42}
@@ -42,10 +67,14 @@ The class to use when highlighting typed text on items. Only used when highlight
**highlightTyped**:
Wether to highlight (style) typed text on items. Default is true.
+**label**:
+The name of the `label` key in your data. The label is what will be shown on each item in the autocomplete list.
+
**maximumItems**:
How many items you want to show when the autocomplete is displayed. Default is 5. Set to 0 to display all available items.
-**onInput**
+**onInput**:
+A callback function to execute on user input.
**onSelectItem**:
A callback that is fired every time an item is selected. It receives an object in following format:
@@ -55,6 +84,9 @@ A callback that is fired every time an item is selected. It receives an object i
**treshold**:
The number of characters that need to be typed on the input in order to trigger the autocomplete. Default is 4.
+**value**:
+The name of the `value` key in your data.
+
### License
-MIT \ No newline at end of file
+MIT