File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,10 @@ var selectize = $select[0].selectize;
195
195
<td valign="top"><code>isFull()</code></td>
196
196
<td valign="top">Returns whether or not the user can select more items.</td>
197
197
</tr>
198
+ <tr>
199
+ <td valign="top"><code>clearCache(template)</code></td>
200
+ <td valign="top">Clears the render cache. Takes an optional template argument (e.g. "option", "item") to clear only that cache.</td>
201
+ </tr>
198
202
</table >
199
203
200
204
### Related Objects
Original file line number Diff line number Diff line change @@ -1913,6 +1913,23 @@ $.extend(Selectize.prototype, {
1913
1913
}
1914
1914
1915
1915
return html ;
1916
+ } ,
1917
+
1918
+ /**
1919
+ * Clears the render cache for a template. If
1920
+ * no template is given, clears all render
1921
+ * caches.
1922
+ *
1923
+ * @param {string } templateName
1924
+ */
1925
+ clearCache : function ( templateName ) {
1926
+ var self = this ;
1927
+ if ( typeof templateName === 'undefined' ) {
1928
+ self . renderCache = { } ;
1929
+ } else {
1930
+ delete self . renderCache [ templateName ] ;
1931
+ }
1916
1932
}
1917
1933
1934
+
1918
1935
} ) ;
Original file line number Diff line number Diff line change 567
567
} ) ;
568
568
} ) ;
569
569
570
+ describe ( 'clearCache()' , function ( ) {
571
+ var test ;
572
+
573
+ before ( function ( ) {
574
+ test = setup_test ( '<select multiple>' , {
575
+ valueField : 'value' ,
576
+ labelField : 'value' ,
577
+ options : [
578
+ { value : 0 } ,
579
+ { value : 1 } ,
580
+ { value : 2 } ,
581
+ { value : 3 } ,
582
+ ] ,
583
+ items : [ '1' , '2' , '3' ]
584
+ } ) ;
585
+ test . selectize . advanceSelection ( 1 ) ;
586
+ test . selectize . refreshOptions ( true ) ;
587
+ test . selectize . refreshItems ( ) ;
588
+ } ) ;
589
+ it ( 'should clear the whole renderCache' , function ( ) {
590
+ expect ( $ . isEmptyObject ( test . selectize . renderCache ) ) . to . be . equal ( false ) ;
591
+ test . selectize . clearCache ( ) ;
592
+ expect ( $ . isEmptyObject ( test . selectize . renderCache ) ) . to . be . equal ( true ) ;
593
+ } ) ;
594
+ it ( 'should allow clearing just one template type from the renderCache' , function ( ) {
595
+ test . selectize . render ( 'item' , test . selectize . options [ 0 ] ) ;
596
+ test . selectize . refreshOptions ( ) ;
597
+ expect ( $ . isEmptyObject ( test . selectize . renderCache [ 'option' ] ) ) . to . be . equal ( false ) ;
598
+ expect ( $ . isEmptyObject ( test . selectize . renderCache [ 'item' ] ) ) . to . be . equal ( false ) ;
599
+ test . selectize . clearCache ( 'option' ) ;
600
+ expect ( $ . isEmptyObject ( test . selectize . renderCache [ 'option' ] ) ) . to . be . equal ( true ) ;
601
+ expect ( $ . isEmptyObject ( test . selectize . renderCache [ 'item' ] ) ) . to . be . equal ( false ) ;
602
+ } ) ;
603
+ } ) ;
604
+
570
605
} ) ;
571
606
572
607
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments