File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,13 @@ $.extend(Selectize.prototype, {
193
193
self . ignoreHover = false ;
194
194
} ) ;
195
195
196
+ // store original children and tab index so that they can be
197
+ // restored when the destroy() method is called.
198
+ this . revertSettings = {
199
+ $children : self . $input . children ( ) . detach ( ) ,
200
+ tabindex : self . $input . attr ( 'tabindex' )
201
+ } ;
202
+
196
203
self . $input . attr ( 'tabindex' , - 1 ) . hide ( ) . after ( self . $wrapper ) ;
197
204
198
205
if ( $ . isArray ( settings . items ) ) {
@@ -1735,12 +1742,18 @@ $.extend(Selectize.prototype, {
1735
1742
destroy : function ( ) {
1736
1743
var self = this ;
1737
1744
var eventNS = self . eventNS ;
1745
+ var revertSettings = self . revertSettings ;
1738
1746
1739
1747
self . trigger ( 'destroy' ) ;
1740
1748
self . off ( ) ;
1741
1749
self . $wrapper . remove ( ) ;
1742
1750
self . $dropdown . remove ( ) ;
1743
- self . $input . show ( ) ;
1751
+
1752
+ self . $input
1753
+ . html ( '' )
1754
+ . append ( revertSettings . $children )
1755
+ . attr ( { tabindex : revertSettings . tabindex } )
1756
+ . show ( ) ;
1744
1757
1745
1758
$ ( window ) . off ( eventNS ) ;
1746
1759
$ ( document ) . off ( eventNS ) ;
Original file line number Diff line number Diff line change 535
535
test . selectize . destroy ( ) ;
536
536
expect ( has_namespaced_event ( $ ( 'body' ) , test . selectize . eventNS ) ) . to . be . equal ( false ) ;
537
537
} ) ;
538
+ it ( 'should restore original options and tabindex' , function ( ) {
539
+ var children = '<optgroup label="Swedish Cars">' +
540
+ '<option value="volvo">Volvo</option>' +
541
+ '<option value="saab">Saab</option>' +
542
+ '</optgroup>' +
543
+ '<optgroup label="German Cars">' +
544
+ '<option value="mercedes">Mercedes</option>' +
545
+ '<option value="audi">Audi</option>' +
546
+ '</optgroup>' ;
547
+ var test = setup_test ( '<select tabindex="9999">' + children + '</select>' , { } ) ;
548
+ test . selectize . destroy ( ) ;
549
+ expect ( test . $select . html ( ) ) . to . be . equal ( children ) ;
550
+ expect ( test . $select . attr ( 'tabindex' ) ) . to . be . equal ( '9999' ) ;
551
+ } ) ;
538
552
} ) ;
539
553
540
554
} ) ;
You can’t perform that action at this time.
0 commit comments