@@ -8,9 +8,6 @@ import { toTitleCase } from '../common/utils/string.mjs'
88const BASE_NAME = 'f-autocomplete'
99const HIGHLIGHT_CLASS_NAME = 'highlight-component'
1010
11- let lastCache = Date . now ( )
12- let optionsCache
13-
1411/**
1512 * Counts the number of occurences of a string in an array of strings
1613 * @param {Array } arr labels
@@ -93,6 +90,8 @@ export const componentOptions = selectedId => {
9390 * Output an autocomplete form element
9491 */
9592export default class Autocomplete {
93+ lastCache = Date . now ( )
94+ optionsCache = null
9695 /**
9796 * Create an Autocomplete instance
9897 * @param {String } key - The key for the autocomplete instance
@@ -201,6 +200,8 @@ export default class Autocomplete {
201200
202201 this . hiddenField . value = value
203202 this . value = value
203+
204+ this . setValue ( { dataset : { label : value , value } } )
204205 } ,
205206 }
206207
@@ -244,13 +245,13 @@ export default class Autocomplete {
244245 }
245246
246247 updateOptions ( ) {
247- let options = optionsCache
248+ let options = this . optionsCache
248249 const now = Date . now ( )
249250
250- if ( ! options || now - lastCache > ANIMATION_SPEED_SLOW * 10 ) {
251+ if ( ! options || now - this . lastCache > ANIMATION_SPEED_SLOW * 10 ) {
251252 dom . empty ( this . list )
252253 options = this . generateOptions ( )
253- lastCache = now
254+ this . lastCache = now
254255 }
255256
256257 if ( ! this . list . children . length ) {
@@ -268,7 +269,7 @@ export default class Autocomplete {
268269 return target
269270 }
270271
271- optionsCache = options . map ( optionData => {
272+ this . optionsCache = options . map ( optionData => {
272273 const { value, textLabel, htmlLabel } = optionData
273274 const optionConfig = {
274275 tag : 'li' ,
@@ -295,7 +296,7 @@ export default class Autocomplete {
295296 return dom . create ( optionConfig )
296297 } )
297298
298- return optionsCache
299+ return this . optionsCache
299300 }
300301
301302 setListPosition ( ) {
0 commit comments