File tree Expand file tree Collapse file tree 4 files changed +109
-1
lines changed Expand file tree Collapse file tree 4 files changed +109
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,25 @@ <h2>Plugin: "remove_button"</h2>
48
48
</ script >
49
49
</ div >
50
50
51
+ < div class ="demo ">
52
+ < h2 > Plugin: "clear_button"</ h2 >
53
+ < div class ="control-group ">
54
+ < label for ="input-clear "> Tags:</ label >
55
+ < input type ="text " id ="input-clear " class ="input-clear demo-default " value ="awesome,neat ">
56
+ </ div >
57
+ < div class ="control-group ">
58
+ < label for ="input-clear-disable "> Tags:</ label >
59
+ < input type ="text " disabled id ="input-clear-disable " class ="input-clear demo-default " value ="awesome,neat ">
60
+ </ div >
61
+ < script >
62
+ $ ( '.input-clear' ) . selectize ( {
63
+ plugins : [ 'clear_button' ] ,
64
+ persist : false ,
65
+ create : true
66
+ } ) ;
67
+ </ script >
68
+ </ div >
69
+
51
70
< div class ="demo ">
52
71
< h2 > Plugin: "restore_on_backspace"</ h2 >
53
72
< div class ="control-group ">
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Plugin: "clear_button" (selectize.js)
3
+ * Copyright (c) 2017 Alexey Kolotovchenkov & contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ * @author Alexey Kolotovchenkov <[email protected] >
15
+ */
16
+
17
+ Selectize . define ( 'clear_button' , function ( options ) {
18
+ var self = this ;
19
+
20
+ options = $ . extend ( {
21
+ label : '×' ,
22
+ title : 'Clear' ,
23
+ className : 'clear'
24
+ } , options ) ;
25
+
26
+ self . setup = ( function ( ) {
27
+ var original = self . setup ;
28
+ return function ( ) {
29
+ original . apply ( self , arguments ) ;
30
+
31
+ var html = '<a href="javascript:void(0)" class="' + options . className + '" tabindex="-1" title="' + escape_html ( options . title ) + '">' + options . label + '</a>' ;
32
+
33
+ self . $control . append ( html ) ;
34
+
35
+ // add event listener
36
+ self . $control
37
+ . on ( 'mousedown' , 'a.' + options . className , function ( e ) {
38
+ // prevent toggling
39
+ e . preventDefault ( ) ;
40
+ e . stopPropagation ( ) ;
41
+ } )
42
+ . on ( 'click' , 'a.' + options . className , function ( e ) {
43
+ e . preventDefault ( ) ;
44
+ e . stopPropagation ( ) ;
45
+ if ( self . isLocked ) return ;
46
+
47
+ self . clear ( ) ;
48
+ self . close ( ) ;
49
+ } ) ;
50
+ } ;
51
+ } ) ( ) ;
52
+ } ) ;
Original file line number Diff line number Diff line change
1
+ .selectize-control.plugin-clear_button {
2
+ & .single .selectize-input :after {
3
+ content : none ;
4
+ }
5
+
6
+ .clear {
7
+ display : none ;
8
+ position : absolute ;
9
+ top : @selectize-padding-y ;
10
+ right : @selectize-padding-item-x ;
11
+ font-size : 1.5em ;
12
+ padding : @selectize-padding-item-y @selectize-padding-item-x ;
13
+ color : @selectize-color-border ;
14
+ outline : 0 ;
15
+
16
+ & :hover {
17
+ color : @selectize-color-text ;
18
+ }
19
+ }
20
+
21
+ .selectize-input.has-items {
22
+ .clear {
23
+ display : inline-block ;
24
+ }
25
+ }
26
+
27
+ .disabled {
28
+ .clear {
29
+ color : @selectize-color-border ;
30
+ }
31
+ }
32
+
33
+ & .single .selectize-input.has-items ,
34
+ & .multi .selectize-input.has-items {
35
+ padding-right : @selectize-padding-x + 2 * @selectize-padding-item-x ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change @@ -1811,7 +1811,7 @@ $.extend(Selectize.prototype, {
1811
1811
var self = this ;
1812
1812
1813
1813
if ( ! self . items . length ) return ;
1814
- self . $control . children ( ':not(input) ' ) . remove ( ) ;
1814
+ self . $control . children ( '[data-value] ' ) . remove ( ) ;
1815
1815
self . items = [ ] ;
1816
1816
self . lastQuery = null ;
1817
1817
self . setCaret ( 0 ) ;
You can’t perform that action at this time.
0 commit comments