I happened to run this module in an environment where Array.prototype had two methods added ("last" and "contains" btw). And I was wondering why two undefined elements are showing up at the end of the list of items, until I realized that is why. Well. Basically if you use "for (var n in ...)" then it also enumerates the extended prototype elements, so does not work well for when you have Array extended. There is no options['last'] element in the array from the parsing of options really, so you'll end up with undefined.
To reproduce the bug, just try to pop in any of these samples to your JS and go to an options element form: http://www.go4expert.com/forums/showthread.php?t=606 You'll see a number of undefined elements equal to how many custom methods you've added.
The suggested patch just uses the boring regular for syntax to avoid running into non-numeric indexes on the arrays.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | defaults-varnamefix.patch | 797 bytes | gábor hojtsy |
| no-var-n-in.patch | 2.07 KB | gábor hojtsy |
Comments
Comment #1
JacobSingh commentedYep, it's a better way to do this.
Comment #2
quicksketchI'll put this in next time I'm working on Options Element.
Comment #3
quicksketchThanks committed to both Options Element branches.
Comment #4
gábor hojtsyUps, looks like I broke this one with a bad variable name there... Too much copy-pasting in there. Look how the second hunk in http://drupal.org/files/issues/no-var-n-in.patch above changes default to options. Ups. Please find my patch and accept my apology.
Comment #5
quicksketchThanks Gábor. Committed the fix.