AuraQ / AutoCompleteForMendix

An autocomplete widget for mendix
Apache License 2.0
8 stars 31 forks source link

Cannot read properties of null (reading 'toLowerCase') #98

Open stephanbruijnis opened 6 months ago

stephanbruijnis commented 6 months ago

There is an issue with the widget when sometimes it cannot process the following code:

                                if( attributeValue.toLowerCase().lastIndexOf(self._currentSearchTerm.toLowerCase(), 0) === 0 ){
                                filteredObjs.push(self._localObjectCache[i]);

It will show an error in the browser console:

mxui.js?638440481067909697:64 [Client] TypeError: Cannot read properties of null (reading 'toLowerCase')
    at request (widgets.js?638440481067909697:8080:48)

Issue also discussed here: https://community.mendix.com/link/space/widgets/questions/93784

a fix would be to wrap the following code in an if check if(attributeValue !== null)

                        if(self.cacheSearchMethod == "startswith"){
                            // startsWith not supported in IE
                            //if( attributeValue.toLowerCase().startsWith(self._currentSearchTerm.toLowerCase()) ){
                            if( attributeValue.toLowerCase().lastIndexOf(self._currentSearchTerm.toLowerCase(), 0) === 0 ){
                                filteredObjs.push(self._localObjectCache[i]);
                            }
                        }
                        else{
                            if( attributeValue.toLowerCase().indexOf(self._currentSearchTerm.toLowerCase()) >= 0 ){
                                filteredObjs.push(self._localObjectCache[i]);
                            }
                        }