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.

Comments

JacobSingh’s picture

Status: Needs review » Reviewed & tested by the community

Yep, it's a better way to do this.

quicksketch’s picture

I'll put this in next time I'm working on Options Element.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks committed to both Options Element branches.

gábor hojtsy’s picture

Status: Fixed » Needs review
StatusFileSize
new797 bytes

Ups, 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.

quicksketch’s picture

Status: Needs review » Fixed

Thanks Gábor. Committed the fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.