@tarekraafat/autocomplete.js
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -95,3 +95,3 @@ (function (global, factory) { | ||
event: event, | ||
query: getInput(field).value, | ||
query: getInput(field) instanceof HTMLInputElement ? getInput(field).value : getInput(field).innerHTML, | ||
matches: resultsValues.matches, | ||
@@ -159,2 +159,3 @@ results: resultsValues.list.map(function (record) { | ||
}; | ||
this.noResults = config.noResults; | ||
this.highlight = config.highlight || false; | ||
@@ -200,6 +201,5 @@ this.onSelection = config.onSelection; | ||
var resList = []; | ||
var inputValue = autoCompleteView.getInput(_this.selector).value.toLowerCase(); | ||
data.filter(function (record, index) { | ||
var search = function search(key) { | ||
var match = _this.search(inputValue, record[key] || record); | ||
var match = _this.search(_this.inputValue, record[key] || record); | ||
if (match && key) { | ||
@@ -279,18 +279,23 @@ resList.push({ | ||
var exec = function exec(event) { | ||
_this2.inputValue = input instanceof HTMLInputElement ? input.value : input.innerHTML; | ||
var resultsList = _this2.resultsList; | ||
var clearResults = autoCompleteView.clearResults(resultsList); | ||
if (input.value.length > _this2.threshold && input.value.replace(/ /g, "").length) { | ||
if (_this2.inputValue.length > _this2.threshold && _this2.inputValue.replace(/ /g, "").length) { | ||
_this2.listMatchedResults(_this2.dataSrc).then(function (list) { | ||
input.dispatchEvent(new CustomEvent("type", { | ||
bubbles: true, | ||
detail: { | ||
event: event, | ||
query: input.value, | ||
matches: list.matches, | ||
results: list.list | ||
}, | ||
cancelable: true | ||
})); | ||
if (onSelection) { | ||
autoCompleteView.getSelection(selector, resultsList, onSelection, list); | ||
if (list.list.length === 0) { | ||
_this2.noResults(); | ||
} else { | ||
input.dispatchEvent(new CustomEvent("type", { | ||
bubbles: true, | ||
detail: { | ||
event: event, | ||
query: _this2.inputValue, | ||
matches: list.matches, | ||
results: list.list | ||
}, | ||
cancelable: true | ||
})); | ||
if (onSelection) { | ||
autoCompleteView.getSelection(selector, resultsList, onSelection, list); | ||
} | ||
} | ||
@@ -297,0 +302,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
var a,b;a=this,b=function(){"use strict";function i(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}var o="data-result",l={resultsList:"autoComplete_results_list",result:"autoComplete_result",highlight:"autoComplete_highlighted"},u=function(t){return"string"==typeof t?document.querySelector(t):t()},c=function(t){return t.innerHTML=""},h=u,r=function(t){var e=document.createElement(t.element);return t.container&&(l.resultsList=t.container(e)||l.resultsList),e.setAttribute("id",l.resultsList),t.destination.insertAdjacentElement(t.position,e),e},d=function(t){return"<span class=".concat(l.highlight,">").concat(t,"</span>")},a=function(i,r,a){r.forEach(function(t,e){var n=document.createElement(a.element),s=r[e].value[t.key]||r[e].value;n.setAttribute(o,s),n.setAttribute("class",l.result),n.setAttribute("tabindex","1"),n.innerHTML=a.content?a.content(t,n):t.match||t,i.appendChild(n)})},f=function(t,n){var s=u(t),i=n.firstChild;document.onkeydown=function(t){var e=document.activeElement;switch(t.keyCode){case 38:e!==i&&e!==s?e.previousSibling.focus():e===i&&s.focus();break;case 40:e===s&&0<n.childNodes.length?i.focus():e!==n.lastChild&&e.nextSibling.focus()}}},m=c,v=function(n,s,i,r){var a=s.querySelectorAll(".".concat(l.result));Object.keys(a).forEach(function(e){["mousedown","keydown"].forEach(function(t){a[e].addEventListener(t,function(e){"mousedown"!==t&&13!==e.keyCode&&39!==e.keyCode||(i({event:e,query:u(n).value,matches:r.matches,results:r.list.map(function(t){return t.value}),selection:r.list.find(function(t){return(t.value[t.key]||t.value)===e.target.closest(".".concat(l.result)).getAttribute(o)})}),c(s))})})})};return function(){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.selector=t.selector||"#autoComplete",this.data={src:function(){return"function"==typeof t.data.src?t.data.src():t.data.src},key:t.data.key,cache:void 0===t.data.cache||t.data.cache},this.searchEngine="loose"===t.searchEngine?"loose":"strict",this.threshold=t.threshold||0,this.debounce=t.debounce||0,this.resultsList=r({container:!(!t.resultsList||!t.resultsList.container)&&t.resultsList.container,destination:t.resultsList&&t.resultsList.destination?t.resultsList.destination:h(this.selector),position:t.resultsList&&t.resultsList.position?t.resultsList.position:"afterend",element:t.resultsList&&t.resultsList.element?t.resultsList.element:"ul"}),this.sort=t.sort||!1,this.placeHolder=t.placeHolder,this.maxResults=t.maxResults||5,this.resultItem={content:!(!t.resultItem||!t.resultItem.content)&&t.resultItem.content,element:t.resultItem&&t.resultItem.element?t.resultItem.element:"li"},this.highlight=t.highlight||!1,this.onSelection=t.onSelection,this.dataSrc,this.init()}var t,n,s;return t=e,(n=[{key:"search",value:function(t,e){var n=this.highlight,s=e.toLowerCase();if("loose"===this.searchEngine){t=t.replace(/ /g,"");for(var i=[],r=0,a=0;a<s.length;a++){var o=e[a];r<t.length&&s[a]===t[r]&&(o=n?d(o):o,r++),i.push(o)}return r===t.length&&i.join("")}if(s.includes(t))return t=new RegExp("".concat(t),"i").exec(e),n?e.replace(t,d(t)):e}},{key:"listMatchedResults",value:function(n){var c=this;return new Promise(function(t){var l=[],u=h(c.selector).value.toLowerCase();n.filter(function(n,s){var t=function(t){var e=c.search(u,n[t]||n);e&&t?l.push({key:t,index:s,match:e,value:n}):e&&!t&&l.push({index:s,match:e,value:n})};if(c.data.key){var e=!0,i=!1,r=void 0;try{for(var a,o=c.data.key[Symbol.iterator]();!(e=(a=o.next()).done);e=!0){t(a.value)}}catch(t){i=!0,r=t}finally{try{e||null==o.return||o.return()}finally{if(i)throw r}}}else t()});var e=c.sort?l.sort(c.sort).slice(0,c.maxResults):l.slice(0,c.maxResults);return a(c.resultsList,e,c.resultItem),f(c.selector,c.resultsList),t({matches:l.length,list:e})})}},{key:"ignite",value:function(){var s=this,i=this.selector,r=h(i),t=this.placeHolder,a=this.onSelection;t&&r.setAttribute("placeholder",t);var n,o,l,u=function(e){var n=s.resultsList;m(n);r.value.length>s.threshold&&r.value.replace(/ /g,"").length&&s.listMatchedResults(s.dataSrc).then(function(t){r.dispatchEvent(new CustomEvent("type",{bubbles:!0,detail:{event:e,query:r.value,matches:t.matches,results:t.list},cancelable:!0})),a&&v(i,n,a,t)})};r.addEventListener("keyup",(n=function(e){if(s.data.cache)u(e);else{var t=s.data.src();t instanceof Promise?t.then(function(t){s.dataSrc=t,u(e)}):(s.dataSrc=t,u(e))}},o=this.debounce,function(){var t=this,e=arguments;clearTimeout(l),l=setTimeout(function(){return n.apply(t,e)},o)}))}},{key:"init",value:function(){var e=this,t=this.data.src();t instanceof Promise?t.then(function(t){e.dataSrc=t,e.ignite()}):(this.dataSrc=t,this.ignite())}}])&&i(t.prototype,n),s&&i(t,s),e}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.autoComplete=b(); | ||
var a,b;a=this,b=function(){"use strict";function i(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}var l="data-result",o={resultsList:"autoComplete_results_list",result:"autoComplete_result",highlight:"autoComplete_highlighted"},u=function(t){return"string"==typeof t?document.querySelector(t):t()},c=function(t){return t.innerHTML=""},h=u,r=function(t){var e=document.createElement(t.element);return t.container&&(o.resultsList=t.container(e)||o.resultsList),e.setAttribute("id",o.resultsList),t.destination.insertAdjacentElement(t.position,e),e},d=function(t){return"<span class=".concat(o.highlight,">").concat(t,"</span>")},a=function(i,r,a){r.forEach(function(t,e){var n=document.createElement(a.element),s=r[e].value[t.key]||r[e].value;n.setAttribute(l,s),n.setAttribute("class",o.result),n.setAttribute("tabindex","1"),n.innerHTML=a.content?a.content(t,n):t.match||t,i.appendChild(n)})},f=function(t,n){var s=u(t),i=n.firstChild;document.onkeydown=function(t){var e=document.activeElement;switch(t.keyCode){case 38:e!==i&&e!==s?e.previousSibling.focus():e===i&&s.focus();break;case 40:e===s&&0<n.childNodes.length?i.focus():e!==n.lastChild&&e.nextSibling.focus()}}},m=c,v=function(n,s,i,r){var a=s.querySelectorAll(".".concat(o.result));Object.keys(a).forEach(function(e){["mousedown","keydown"].forEach(function(t){a[e].addEventListener(t,function(e){"mousedown"!==t&&13!==e.keyCode&&39!==e.keyCode||(i({event:e,query:u(n)instanceof HTMLInputElement?u(n).value:u(n).innerHTML,matches:r.matches,results:r.list.map(function(t){return t.value}),selection:r.list.find(function(t){return(t.value[t.key]||t.value)===e.target.closest(".".concat(o.result)).getAttribute(l)})}),c(s))})})})};return function(){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.selector=t.selector||"#autoComplete",this.data={src:function(){return"function"==typeof t.data.src?t.data.src():t.data.src},key:t.data.key,cache:void 0===t.data.cache||t.data.cache},this.searchEngine="loose"===t.searchEngine?"loose":"strict",this.threshold=t.threshold||0,this.debounce=t.debounce||0,this.resultsList=r({container:!(!t.resultsList||!t.resultsList.container)&&t.resultsList.container,destination:t.resultsList&&t.resultsList.destination?t.resultsList.destination:h(this.selector),position:t.resultsList&&t.resultsList.position?t.resultsList.position:"afterend",element:t.resultsList&&t.resultsList.element?t.resultsList.element:"ul"}),this.sort=t.sort||!1,this.placeHolder=t.placeHolder,this.maxResults=t.maxResults||5,this.resultItem={content:!(!t.resultItem||!t.resultItem.content)&&t.resultItem.content,element:t.resultItem&&t.resultItem.element?t.resultItem.element:"li"},this.noResults=t.noResults,this.highlight=t.highlight||!1,this.onSelection=t.onSelection,this.dataSrc,this.init()}var t,n,s;return t=e,(n=[{key:"search",value:function(t,e){var n=this.highlight,s=e.toLowerCase();if("loose"===this.searchEngine){t=t.replace(/ /g,"");for(var i=[],r=0,a=0;a<s.length;a++){var l=e[a];r<t.length&&s[a]===t[r]&&(l=n?d(l):l,r++),i.push(l)}return r===t.length&&i.join("")}if(s.includes(t))return t=new RegExp("".concat(t),"i").exec(e),n?e.replace(t,d(t)):e}},{key:"listMatchedResults",value:function(n){var u=this;return new Promise(function(t){var o=[];n.filter(function(n,s){var t=function(t){var e=u.search(u.inputValue,n[t]||n);e&&t?o.push({key:t,index:s,match:e,value:n}):e&&!t&&o.push({index:s,match:e,value:n})};if(u.data.key){var e=!0,i=!1,r=void 0;try{for(var a,l=u.data.key[Symbol.iterator]();!(e=(a=l.next()).done);e=!0){t(a.value)}}catch(t){i=!0,r=t}finally{try{e||null==l.return||l.return()}finally{if(i)throw r}}}else t()});var e=u.sort?o.sort(u.sort).slice(0,u.maxResults):o.slice(0,u.maxResults);return a(u.resultsList,e,u.resultItem),f(u.selector,u.resultsList),t({matches:o.length,list:e})})}},{key:"ignite",value:function(){var s=this,i=this.selector,r=h(i),t=this.placeHolder,a=this.onSelection;t&&r.setAttribute("placeholder",t);var n,l,o,u=function(e){s.inputValue=r instanceof HTMLInputElement?r.value:r.innerHTML;var n=s.resultsList;m(n);s.inputValue.length>s.threshold&&s.inputValue.replace(/ /g,"").length&&s.listMatchedResults(s.dataSrc).then(function(t){0===t.list.length?s.noResults():(r.dispatchEvent(new CustomEvent("type",{bubbles:!0,detail:{event:e,query:s.inputValue,matches:t.matches,results:t.list},cancelable:!0})),a&&v(i,n,a,t))})};r.addEventListener("keyup",(n=function(e){if(s.data.cache)u(e);else{var t=s.data.src();t instanceof Promise?t.then(function(t){s.dataSrc=t,u(e)}):(s.dataSrc=t,u(e))}},l=this.debounce,function(){var t=this,e=arguments;clearTimeout(o),o=setTimeout(function(){return n.apply(t,e)},l)}))}},{key:"init",value:function(){var e=this,t=this.data.src();t instanceof Promise?t.then(function(t){e.dataSrc=t,e.ignite()}):(this.dataSrc=t,this.ignite())}}])&&i(t.prototype,n),s&&i(t,s),e}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.autoComplete=b(); |
@@ -17,3 +17,3 @@ // autoComplete.js on type event emitter | ||
}, | ||
key: ["food", "cities", "animals"], | ||
key: ["food", "cities", "animals"] | ||
}, | ||
@@ -47,2 +47,9 @@ sort: (a, b) => { | ||
}, | ||
noResults: () => { | ||
const result = document.createElement("li"); | ||
result.setAttribute("class", "no_result"); | ||
result.setAttribute("tabindex", "1"); | ||
result.innerHTML = "No Results"; | ||
document.querySelector("#autoComplete_results_list").appendChild(result); | ||
}, | ||
onSelection: feedback => { | ||
@@ -49,0 +56,0 @@ const selection = feedback.selection.value.food; |
@@ -5,3 +5,3 @@ <a href="https://tarekraafat.github.io/autoComplete.js/demo/"> | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">Live Demo</a> **v5.0** | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">Live Demo</a> **v5.1** | ||
@@ -8,0 +8,0 @@ autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed,<br>high versatility and seamless integration with wide range of projects & systems. |
@@ -53,2 +53,9 @@ // autoComplete.js on type event emitter | ||
}, | ||
noResults: () => { | ||
const result = document.createElement("li"); | ||
result.setAttribute("class", "no_result"); | ||
result.setAttribute("tabindex", "1"); | ||
result.innerHTML = "No Results"; | ||
document.querySelector("#autoComplete_results_list").appendChild(result); | ||
}, | ||
onSelection: feedback => { | ||
@@ -55,0 +62,0 @@ const title = feedback.selection.value.title; |
@@ -8,2 +8,3 @@ # Introduction | ||
[![](https://data.jsdelivr.com/v1/package/gh/TarekRaafat/autoComplete.js/badge)](https://www.jsdelivr.com/package/gh/TarekRaafat/autoComplete.js) | ||
[![](https://data.jsdelivr.com/v1/package/npm/@tarekraafat/autocomplete.js/badge)](https://www.jsdelivr.com/package/npm/@tarekraafat/autocomplete.js) | ||
![\[Zero Dependencies\]()](https://img.shields.io/badge/Dependencies-0-blue.svg) | ||
@@ -18,3 +19,3 @@ ![\[Size\]()](https://img.shields.io/badge/Size-5%20KB-green.svg) | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">:rocket: Live Demo</a> **v5.0** | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">:rocket: Live Demo</a> **v5.1** | ||
@@ -33,3 +34,3 @@ autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed, high versatility and seamless integration with wide range of projects & systems, made for users and developers in mind. | ||
## [![autoComplete.js Code Example](./img/autoComplete.init.png "autoComplete.js Code Example")](https://codepen.io/tarekraafat/pen/rQopdW) | ||
## [![autoComplete.js Code Example](./img/autoComplete.init.png "autoComplete.js Code Example")](https://codepen.io/tarekraafat/pen/rQopdW?editors=0010) | ||
@@ -73,3 +74,3 @@ ## 1. Get Started | ||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/css/autoComplete.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/css/autoComplete.min.css"> | ||
``` | ||
@@ -80,3 +81,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/js/autoComplete.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/js/autoComplete.min.js"></script> | ||
``` | ||
@@ -123,3 +124,3 @@ | ||
OR | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/css/autoComplete.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/css/autoComplete.min.css"> | ||
``` | ||
@@ -139,3 +140,3 @@ | ||
OR | ||
<script src="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/js/autoComplete.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/js/autoComplete.min.js"></script> | ||
<script src="./js/index.js"></script> | ||
@@ -223,3 +224,3 @@ ``` | ||
- Try it on [<img src="https://cdn.freelogovectors.net/wp-content/uploads/2018/03/codepen-logo.png" width="100px" alt="CodePen">](https://codepen.io/tarekraafat/pen/rQopdW) | ||
- Try it on [<img src="https://cdn.freelogovectors.net/wp-content/uploads/2018/03/codepen-logo.png" width="100px" alt="CodePen">](https://codepen.io/tarekraafat/pen/rQopdW?editors=0010) | ||
@@ -257,3 +258,3 @@ [demo]: https://tarekraafat.github.io/autoComplete.js/demo/ | ||
## 5. What's New in v5.0? | ||
## 5. What's New in v5.1? | ||
@@ -260,0 +261,0 @@ Check out <a href="#/releases?id=versioning">Releases</a> Information :sparkles: |
@@ -29,4 +29,8 @@ ## Versioning | ||
- v5.0.0 :sparkles: | ||
- v5.1.0 :sparkles: | ||
- Added `noResults` open API for No Results (Thanks @chabri) | ||
- HTML elements `ContentEditable` Input Support(Thanks @philippejadin) | ||
- v5.0.0 | ||
- Large datasets handeling (Thanks @Johann-S) | ||
@@ -33,0 +37,0 @@ - API Data fetching & Dynamic Data reloading (Thanks @Brostafa) |
{ | ||
"name": "@tarekraafat/autocomplete.js", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "Simple autocomplete pure vanilla Javascript library.", | ||
@@ -5,0 +5,0 @@ "main": "dist/js/autoComplete.js", |
@@ -8,2 +8,3 @@ # autoComplete.js :sparkles: | ||
[![](https://data.jsdelivr.com/v1/package/gh/TarekRaafat/autoComplete.js/badge)](https://www.jsdelivr.com/package/gh/TarekRaafat/autoComplete.js) | ||
[![](https://data.jsdelivr.com/v1/package/npm/@tarekraafat/autocomplete.js/badge)](https://www.jsdelivr.com/package/npm/@tarekraafat/autocomplete.js) | ||
![\[Zero Dependencies\]()](https://img.shields.io/badge/Dependencies-0-blue.svg) | ||
@@ -23,3 +24,3 @@ ![\[Size\]()](https://img.shields.io/badge/Size-5%20KB-green.svg) | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">:rocket: Live Demo</a> **v5.0** | ||
> Simple autocomplete pure vanilla Javascript library. <a href="https://tarekraafat.github.io/autoComplete.js/demo/" target="\_blank">:rocket: Live Demo</a> **v5.1** | ||
@@ -38,3 +39,3 @@ autoComplete.js is a simple pure vanilla Javascript library that's progressively designed for speed, high versatility and seamless integration with wide range of projects & systems, made for users and developers in mind. | ||
## [![autoComplete.js Code Example](./docs/img/autoComplete.init.png "autoComplete.js Code Example")](https://codepen.io/tarekraafat/pen/rQopdW) | ||
## [![autoComplete.js Code Example](./docs/img/autoComplete.init.png "autoComplete.js Code Example")](https://codepen.io/tarekraafat/pen/rQopdW?editors=0010) | ||
@@ -58,3 +59,3 @@ ## Get Started | ||
```html | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/css/autoComplete.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/css/autoComplete.min.css"> | ||
``` | ||
@@ -65,3 +66,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/gh/TarekRaafat/autoComplete.js@5.0.0/dist/js/autoComplete.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@tarekraafat/autocomplete.js@5.1.0/dist/js/autoComplete.min.js"></script> | ||
``` | ||
@@ -68,0 +69,0 @@ |
@@ -67,2 +67,4 @@ import { autoCompleteView } from "../views/autoCompleteView"; | ||
}; | ||
// No Results action | ||
this.noResults = config.noResults; | ||
// Highlighting matching results | ||
@@ -147,4 +149,2 @@ this.highlight = config.highlight || false; | ||
const resList = []; | ||
// Holds the input search value | ||
const inputValue = autoCompleteView.getInput(this.selector).value.toLowerCase(); | ||
@@ -156,3 +156,3 @@ // Checks input has matches in data source | ||
// Holds match value | ||
const match = this.search(inputValue, record[key] || record); | ||
const match = this.search(this.inputValue, record[key] || record); | ||
// Push match to results list with key if set | ||
@@ -231,2 +231,6 @@ if (match && key) { | ||
const exec = (event) => { | ||
// Gets the input search value | ||
this.inputValue = input instanceof HTMLInputElement | ||
? input.value | ||
: input.innerHTML; | ||
// Get results list value | ||
@@ -238,21 +242,25 @@ const resultsList = this.resultsList; | ||
// Check if input is not empty or just have space before triggering the app | ||
if (input.value.length > this.threshold && input.value.replace(/ /g, "").length) { | ||
if (this.inputValue.length > this.threshold && this.inputValue.replace(/ /g, "").length) { | ||
// List matching results | ||
this.listMatchedResults(this.dataSrc).then(list => { | ||
if (list.list.length === 0) { | ||
this.noResults(); | ||
} else { | ||
// Event emitter on input field | ||
input.dispatchEvent( | ||
new CustomEvent("type", { | ||
bubbles: true, | ||
detail: { | ||
event, | ||
query: input.value, | ||
matches: list.matches, | ||
results: list.list, | ||
}, | ||
cancelable: true, | ||
})); | ||
// Gets user's selection | ||
// If action configured | ||
if (onSelection) { | ||
autoCompleteView.getSelection(selector, resultsList, onSelection, list); | ||
input.dispatchEvent( | ||
new CustomEvent("type", { | ||
bubbles: true, | ||
detail: { | ||
event, | ||
query: this.inputValue, | ||
matches: list.matches, | ||
results: list.list, | ||
}, | ||
cancelable: true, | ||
})); | ||
// Gets user's selection | ||
// If action configured | ||
if (onSelection) { | ||
autoCompleteView.getSelection(selector, resultsList, onSelection, list); | ||
} | ||
} | ||
@@ -259,0 +267,0 @@ }); |
@@ -122,3 +122,5 @@ const dataAttribute = "data-result"; | ||
event, | ||
query: getInput(field).value, | ||
query: getInput(field) instanceof HTMLInputElement | ||
? getInput(field).value | ||
: getInput(field).innerHTML, | ||
matches: resultsValues.matches, | ||
@@ -125,0 +127,0 @@ results: resultsValues.list.map(record => record.value), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1367579
11774
111