You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simply import the autocompleter in your typescript file:
53
54
54
55
```javascript
55
-
importautocompletefrom'autocompleter';
56
+
importautocompletefrom"autocompleter";
56
57
```
57
58
58
59
and call the `autocomplete` function as showed below:
@@ -104,24 +105,24 @@ If your interface doesn't have a `label` property, you also have to provide a cu
104
105
105
106
You can pass the following options to `autocomplete`:
106
107
107
-
| Parameter | Description | Default |
108
-
| --------- | ----------- | ------- |
109
-
|`onSelect`|This method will be called when user choose an item in autocomplete. The selected item will be passed as first parameter.|`-`|
110
-
|`input`|DOM input element must be passed with this parameter and autocomplete will attach itself to this field. Selectors are not supported, but you can just use `document.querySelector('...')` to find the required element.|`-`|
111
-
|`minLength`|Specify the minimum length, when autocomplete should appear on the screen.|`2`|
112
-
|`emptyMsg`|The message that will be showed when there are no suggestions that match the entered value.|`undefined`|
113
-
|`render`|This method allows you to override the rendering function. It will be called for each suggestion and the suggestion object will be passed as first parameter. The current input field value will be passed as second parameter. This function must return a DIV element or `undefined` to skip rendering.|`undefined`|
114
-
|`renderGroup`|The same as `render`, but will be called for each group. The first parameter of the function will be the group name. The current input field value will be passed as second parameter. This function must return a `DIV` element or `undefined` to skip rendering.|`undefined`|
115
-
|`className`|The autocomplete container will have this class name if specified.|`undefined`|
116
-
|`fetch`|This method will be called to prepare suggestions and then pass them to autocomplete. The first parameter is the text in the input field. The second parameter is a callback function that must be called after suggestions are prepared with an array as parameter. If you pass `false` to the callback function, autocomplete will show previous suggestions and will not re-render.|`-`|
117
-
|`debounceWaitMs`|Enforces that the `fetch` function will only be called once within the specified time frame (in milliseconds) and delays execution. This prevents flooding your server with AJAX requests.|`0`|
118
-
|`customize`|Callback for additional autocomplete customization after rendering is finished. Use this function if you want to change autocomplete default position.|`undefined`|
119
-
|`preventSubmit`|This option controls form submission when the ENTER key is pressed in a input field. Three settings are available: `Never`, `Always`, and `OnSelect`. Choose the appropriate setting to customize form submission behavior as per your needs.|`Never`|
120
-
|`showOnFocus`|Displays suggestions on focus of the input element. Note that if `true`, the minLength property will be ignored and it will always call `fetch`.|`false`|
121
-
|`disableAutoSelect`|Prevents the first item in the list from being selected automatically. This option allows you to submit a custom text by pressing `ENTER` even when autocomplete is displayed.|`false`|
122
-
|`container`|Provide your own container for the widget. If not specified, a new DIV element will be created.|`undefined`|
123
-
|`click`|Allows to display autocomplete on mouse clicks or perform some additional actions.|`undefined`|
124
-
|`keyup`|Allows to display autocomplete when a key is pressed that doesn't modify the content.|see code|
|`onSelect`|This method will be called when user choose an item in autocomplete. The selected item will be passed as first parameter.|`-`|
111
+
|`input`|DOM input element must be passed with this parameter and autocomplete will attach itself to this field. Selectors are not supported, but you can just use `document.querySelector('...')` to find the required element.|`-`|
112
+
|`minLength`|Specify the minimum length, when autocomplete should appear on the screen.|`2`|
113
+
|`emptyMsg`|The message that will be showed when there are no suggestions that match the entered value.|`undefined`|
114
+
|`render`|This method allows you to override the rendering function. It will be called for each suggestion and the suggestion object will be passed as first parameter. The current input field value will be passed as second parameter. This function must return a DIV element or `undefined` to skip rendering.|`undefined`|
115
+
|`renderGroup`|The same as `render`, but will be called for each group. The first parameter of the function will be the group name. The current input field value will be passed as second parameter. This function must return a `DIV` element or `undefined` to skip rendering.|`undefined`|
116
+
|`className`|The autocomplete container will have this class name if specified.|`undefined`|
117
+
|`fetch`|This method will be called to prepare suggestions and then pass them to autocomplete. The first parameter is the text in the input field. The second parameter is a callback function that must be called after suggestions are prepared with an array as parameter. If you pass `false` to the callback function, autocomplete will show previous suggestions and will not re-render.|`-`|
118
+
|`debounceWaitMs`|Enforces that the `fetch` function will only be called once within the specified time frame (in milliseconds) and delays execution. This prevents flooding your server with AJAX requests.|`0`|
119
+
|`customize`|Callback for additional autocomplete customization after rendering is finished. Use this function if you want to change autocomplete default position.|`undefined`|
120
+
|`preventSubmit`|This option controls form submission when the ENTER key is pressed in a input field. Three settings are available: `Never`, `Always`, and `OnSelect`. Choose the appropriate setting to customize form submission behavior as per your needs.|`Never`|
121
+
|`showOnFocus`|Displays suggestions on focus of the input element. Note that if `true`, the minLength property will be ignored and it will always call `fetch`.|`false`|
122
+
|`disableAutoSelect`|Prevents the first item in the list from being selected automatically. This option allows you to submit a custom text by pressing `ENTER` even when autocomplete is displayed.|`false`|
123
+
|`container`|Provide your own container for the widget. If not specified, a new DIV element will be created.|`undefined`|
124
+
|`click`|Allows to display autocomplete on mouse clicks or perform some additional actions.|`undefined`|
125
+
|`keyup`|Allows to display autocomplete when a key is pressed that doesn't modify the content.|see code|
125
126
126
127
### Sample config using all options
127
128
@@ -181,17 +182,25 @@ autocomplete({
181
182
If you don't want to pass this function every time, you can also use spread operator to create your own autocomplete version with default implementation:
0 commit comments