angular-multi-select icon indicating copy to clipboard operation
angular-multi-select copied to clipboard

Error selecting Items (TypeError: Cannot convert undefined or null to object)

Open fabiogravina opened this issue 11 years ago • 11 comments

When I click on any items ( selected or not) i get:

TypeError: Cannot convert undefined or null to object at isteven-multi-select.js:443 at angular.js:16174 at e (angular.js:4889) at angular.js:5269

from chrome console, using angular 1.3.14

I get this erro coping the basic example ( Browser ), so same dom and model. Thank you

fabiogravina avatar May 19 '15 10:05 fabiogravina

+1 Debugging the js file shows that the syncItems method is called twice.

thucnc avatar May 20 '15 03:05 thucnc

Hi guys,

Can please help to replicate the issue in JsFiddler or Plunker? Thanks.

isteven avatar May 20 '15 13:05 isteven

hi, I cant reproduce this error but for now, I fixed it by injecting below code into the syncItems method to prevent it being called twice.

if (e.originalEvent.prevent) return;
e.originalEvent.prevent = true;"

I guessed for some reason, 2 divs inside your checkBoxContainer are overlapped making the syncItems called twice.

thucnc avatar May 21 '15 04:05 thucnc

@thucnc ,

Many thanks for the info, much appreciated. I will try to see what is actually happening. Meanwhile, I'll keep the issue open as a reference for people who have similar problem.

isteven avatar May 21 '15 07:05 isteven

This fix works fine for me! thank you

fabiogravina avatar May 21 '15 09:05 fabiogravina

+1.

Seeing the same issue in Chrome. Works in Firefox 37.

The fix recommended by thucnc fixes it.

irizvi avatar May 27 '15 17:05 irizvi

@thucnc fix worked for me. One thing I have noticed is that this only occurs when testing on localhost, in live environment it works well without the fix

fredtma avatar Jun 15 '15 07:06 fredtma

@isteven - is there an update with a fix for this issue? I get the same error as well. (v4.0.0). Cannot convert undefined or null to object, ErrorStack: TypeError: Cannot convert undefined or null to object at /scripts/angular-multi-select/isteven-multi-select.js:442:51 at /scripts/angular.js:16414:28 at completeOutstandingRequest (/scripts/angular.js:4940:10) at /scripts/angular.js:5328:7

On debugging, I find that clickedItem is null inside the $timeout function at:

                clickedItem = angular.copy( item );                                                    
                if ( clickedItem !== null ) {                        
                    $timeout( function() {
                        delete clickedItem[ $scope.indexProperty ];
                        delete clickedItem[ $scope.spacingProperty ];      
                        $scope.onItemClick( { data: clickedItem } );
                        clickedItem = null;                    
                    }, 0 );                                                 
                } 

In my case, the user is rather fast and is able to click the item more than once before its selection state changes.

rijog avatar Oct 15 '15 19:10 rijog

I'm also getting this same error (v4.0.0):

TypeError: Cannot convert undefined or null to object
    at isteven-multi-select.js:443
    at angular.js:16414
    at completeOutstandingRequest (angular.js:4940)
    at angular.js:5328

The fix recommended by @thucnc works, but I'd rather not modify the src as I use bower for dependencies.

Should this really be closed? The bug isn't actually fixed.

JamesWooldridge avatar Jun 08 '16 02:06 JamesWooldridge

@JamesWooldridge ,

I'm not sure myself whether it should stay open or closed. I tried but I was unable to replicate this issue, and so far nobody helped me to replicate their problem in Plunker / JsFiddler.

If that fix works, I suggest you to fork & modify into your repo (or local dev folder).

isteven avatar Jun 08 '16 02:06 isteven

@isteven, Thanks for such wonderful feature js.

I am still looking for this fix. i am using minified version from CDN js. I am not able to make any changes in JS.

If you think this is a fix then could you please update your JS and published new version of it. It would be very helpful for me and rest of the folks.

Note: I think to reproduce this is - select option very quick and randomly.

Looking forward to get this fix.

capture

onkarrajambatwar avatar Oct 01 '16 07:10 onkarrajambatwar