This code ties the searchTextChanged function to the input text field:
this.on('input', {
searchTextSelector: this._searchTextChanged
});
This function gets the value from the _getValueFromEventObject function and displays a trash icon when the value is larger than 0
this._searchTextChanged = function (evt) {
var query = this._getValueFromEventObject(evt);
this.select('searchArea').toggleClass('site-header-search-filled', query.length > 0);
var payload = { 'query': query };
this.trigger(document, 'data:search:query', payload);
};
This function makes the input event value available:
this._getValueFromEventObject = function (evt) {
return evt.target ? (evt.target.value || evt.target[0].value) : '';
};
The problem is if I remove the text from the input field with 'backspace', I get the following error: "Uncaught TypeError: Cannot read property 'value' of undefined"
So the backspace event is undefined within this function, or?