Browse files

fix for github issue #3 (id uniqueness)

  • Loading branch information...
1 parent 33d65f5 commit 41ff0c3e22350de1d6ef7d6625f30d63751a2288 @vicb committed Aug 27, 2010
Showing with 8 additions and 7 deletions.
  1. +8 −7 jquery.bsmselect.js
View
15 jquery.bsmselect.js
@@ -30,14 +30,18 @@
BsmSelect.prototype = {
+ buildUid: function(index) {
+ return this.options.containerClass + index;
+ },
+
/**
* Build the DOM for bsmSelect
*/
buildDom: function() {
var self = this, o = this.options;
- // This loop ensures uniqueness, in case of existing bsmSelects placed by ajax
- while($('#' + o.containerClass + this.uid).size()) { this.uid++; }
+ for (var index = 0; $('#' + this.buildUid(index)).size(); index++) {}
+ this.uid = this.buildUid(index);
this.$select = $('<select>', {
'class': o.selectClass,
@@ -55,10 +59,7 @@
this.$list.addClass(o.listClass);
- this.$container = $('<div>', {
- 'class': o.containerClass,
- id: o.containerClass + this.uid
- });
+ this.$container = $('<div>', { 'class': o.containerClass, id: this.uid });
this.buildSelect();
@@ -152,7 +153,7 @@
* @param {jQuery} $option Model option from the original select
*/
addSelectOption: function ($parent, $option) {
- if (!$option.attr('id')) { $option.attr('id', 'bsm' + this.uid + 'option' + this.optIndex); }
+ if (!$option.attr('id')) { $option.attr('id', this.uid + '-option' + this.optIndex); }
var id = $option.attr('id'),
$O = $('<option>', {
text: $option.text(),

0 comments on commit 41ff0c3

Please sign in to comment.