File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 19
19
*
20
20
*/
21
21
( function ( $ , undefined ) {
22
-
22
+ // Counter used to prevent collisions
23
23
var multiselectID = 0 ;
24
24
var $doc = $ ( document ) ;
25
25
77
77
// factory cannot unbind automatically. Use eventNamespace if on
78
78
// jQuery UI 1.9+, and otherwise fallback to a custom string.
79
79
this . _namespaceID = this . eventNamespace || ( 'multiselect' + multiselectID ) ;
80
+ // bump unique ID after assigning it to the widget instance
81
+ this . multiselectID = multiselectID ++ ;
80
82
81
83
var button = ( this . button = $ ( '<button type="button"><span class="ui-icon ui-icon-triangle-1-s"></span></button>' ) )
82
84
. addClass ( 'ui-multiselect ui-widget ui-state-default ui-corner-all' )
133
135
if ( ! o . multiple ) {
134
136
this . menu . addClass ( 'ui-multiselect-single' ) ;
135
137
}
136
-
137
- // bump unique ID
138
- multiselectID ++ ;
139
138
el . hide ( ) ;
140
139
} ,
141
140
159
158
_makeOption : function ( option ) {
160
159
var title = option . title ? option . title : null ;
161
160
var value = option . value ;
162
- var id = this . element . attr ( 'id' ) || multiselectID ; // unique ID for the label & option tags
163
- var inputID = 'ui-multiselect-' + multiselectID + '-' + ( option . id || id + '-option-' + this . inputIdCounter ++ ) ;
161
+ var id = this . element . attr ( 'id' ) || this . multiselectID ; // unique ID for the label & option tags
162
+ var inputID = 'ui-multiselect-' + this . multiselectID + '-' + ( option . id || id + '-option-' + this . inputIdCounter ++ ) ;
164
163
var isDisabled = option . disabled ;
165
164
var isSelected = option . selected ;
166
165
var labelClasses = [ 'ui-corner-all' ] ;
Original file line number Diff line number Diff line change 127
127
el . multiselect ( "destroy" ) . remove ( ) ;
128
128
} ) ;
129
129
130
+ test ( "multiselectclick with multiple widgets" , function ( ) {
131
+ expect ( 3 ) ;
132
+ var first = $ ( "<select multiple><option value='1'>Option 1</option><option value='2'>Option 2</option></select>" ) . appendTo ( body ) . multiselect ( ) ;
133
+ var second = $ ( "<select multiple><option value='1'>Option 1</option><option value='2'>Option 2</option></select>" ) . appendTo ( body ) . multiselect ( ) ;
134
+ equals ( $ ( '.ui-multiselect' ) . length , 2 , "two mutliselects are on the page" ) ;
135
+ first . multiselect ( "refresh" ) ;
136
+ second . multiselect ( "refresh" ) ;
137
+ $label = $ ( second . multiselect ( "getLabels" ) [ 0 ] ) ;
138
+ $wrongInput = $ ( first . multiselect ( "getLabels" ) [ 0 ] ) . find ( "input" ) ;
139
+ $label . click ( ) ;
140
+ equals ( $label . find ( "input" ) . prop ( "checked" ) , true , "the input for that label should be checked" ) ;
141
+ equals ( $wrongInput . prop ( "checked" ) , false , "the input for the corresponding label on the first widget should not be checked" ) ;
142
+ first . multiselect ( "destroy" ) . remove ( ) ;
143
+ second . multiselect ( "destroy" ) . remove ( ) ;
144
+ } ) ;
145
+
130
146
test ( "multiselectclick" , function ( ) {
131
147
expect ( 28 ) ;
132
148
You can’t perform that action at this time.
0 commit comments