Skip to content

More than 1000 targets results in odd behaviour. #11

@n6151h

Description

@n6151h

Short version: at or about line 324 a DOM ID is composed using Math.random()*1000. The trouble is that if you need more than 1000 IDs, this will overflow that number range (0-999). The quick fix is to increase this to something bigger. (10,000 works for me.) The better fix is to use something other than Math.random, or else maybe use a hash to keep track of numbers already used.

Long version:

I have a (dynamically-generated) table in which each element (TD) is ascribed "colorable" class. I then use $(".colorable").colorpick({...}) to set up pickers for each element. (I tried just setting "click" listeners and create the picker on the fly in the event handler, but this doesn't seem to work all that well.) For most of the tables this problem never shows up. But, as the table size nears 1000 or so elements, the picker would start to behave badly.

To reproduce this, set breakpoints in the onShow and onChange handlers and set a watch on $($(this).data('colpick').el).text().trim()

The first time you click on an element, this variable will be set to the contents of the element clicked on. Normally, this won't change as you change the color in the picker. However, for those elements where the bug shows up, the watch variable will change to some other RANDOM element.

Setting the multiplier on line 324 to 10,000 made the bug go away. This is NOT an acceptable solution; just a quick fix. A better option would be to maintain a class variable that would be updated (a simple, incrementing integer, say?) with each new ID generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions