Issue 354: IE error in DND Object error
Status:  Fixed
Owner: ----
Closed:  Sep 2013
Reported by delij...@gmail.com, Sep 17, 2012
I've added a patch to current 1.2.1 release to check if an inArray contains an non "object". I have this error while dnd.

Regards Josip
foo.patch
1.3 KB   View   Download
Sep 17, 2012
Project Member #1 moo...@wwwendt.de
(No comment was entered for this change.)
Labels: Milestone-Release1.2.2
Oct 3, 2012
Project Member #2 moo...@wwwendt.de
I would like to understand the root cause.
What's the value of 'res', when the error occurs. Can we reproduce it?
Status: Waiting
Oct 6, 2012
Project Member #3 moo...@wwwendt.de
(No comment was entered for this change.)
Labels: -Milestone-Release1.2.2 Milestone-Release1.2.x
Jan 8, 2013
#4 strye...@gmail.com
I think that the use of $.inArray with a string instead of an array is causing the problem.

I noticed in 1.2.2 _onDragEvent (as well as in other places) inArray is being used even though there is no guarantee that the object being passed is an array For example in _onDragEvent under the "enter" case:

after: ((res === true) || (res === "after") || $.inArray("after", res) >= 0)

In the jQuery documentation it indicates that the inArray function's second argument should be an array.  The code seems to work correctly in newer browsers, but I'm running into an issue in IE8 where attempting to drag and drop will cause jQuery (v1.8.2) to generate an error "Object expected".

If I change the code to only do the array check when res is an array, then it will work.  (I'm thinking that this check is similar to what Josip suggested).

In this case, is dynatree expecting that res will always be an array?  Or should we construct a check, similar to Josip's suggestion, that will handle both strings and arrays?

Jan 8, 2013
Project Member #5 moo...@wwwendt.de
Dynatree expects an array but should also work with simple strings.
I guess we should set 
    res = [ res ]; 
if res was passed as string...

Thanks for your analysis
Status: Accepted
Labels: -Milestone-Release1.2.x Milestone-Release1.2.3
Jan 8, 2013
#6 strye...@gmail.com
Thanks for dynatree.  It's a great plugin.

Back to the issue at hand, I'm not sure what you mean by setting res = [res].  Do you mean:
 
   var resArray = new Array();
   resArray.push(res);
 
Sorry if I'm missing something, but I don't see that just changing res will work because it looks like it's being tested as if it were a string in the (res === "after") clause.

   after: ((res === true) || (res === "after") || $.inArray("after", res) >= 0)

So if we did change the argument for inArray we could try something like:

   var resArray = new Array();
   resArray.push(res);

   after: ((res === true) || (res === "after") || $.inArray("after", resArray) >= 0)

Curious, does the res === true and ==="after" work the way you want when res is an array?  I would have though that the comparison would fail because dynatree is trying to compare an array to a bool or string.  Testing in Node, I find that those types of comparisons fail.

Feb 10, 2013
Project Member #7 moo...@wwwendt.de
(No comment was entered for this change.)
Labels: -Milestone-Release1.2.3 Milestone-Release1.2.4
Feb 12, 2013
Project Member #8 moo...@wwwendt.de
1.2.4 was a hotfix
Labels: -Milestone-Release1.2.4 Milestone-Release1.2.5
Sep 8, 2013
Project Member #9 moo...@wwwendt.de
I *think* this should be fixed by now
Status: Fixed