@@ -154,7 +154,7 @@ Selectize.prototype.setup = function() {
154
154
else if ( e . keyCode === KEY_SHIFT ) self . isShiftDown = false ;
155
155
} ,
156
156
mousedown : function ( e ) {
157
- if ( self . isFocused && ! self . isLocked ) {
157
+ if ( self . isFocused ) {
158
158
// prevent events on the dropdown scrollbar from causing the control to blur
159
159
if ( e . target === self . $dropdown [ 0 ] ) {
160
160
var ignoreFocus = self . ignoreFocus ;
@@ -220,7 +220,7 @@ Selectize.prototype.trigger = function(event) {
220
220
* @returns {boolean }
221
221
*/
222
222
Selectize . prototype . onKeyPress = function ( e ) {
223
- if ( this . isLocked ) return ;
223
+ if ( this . isLocked ) return e && e . preventDefault ( ) ;
224
224
var character = String . fromCharCode ( e . keyCode || e . which ) ;
225
225
if ( this . settings . create && character === this . settings . delimiter ) {
226
226
this . createItem ( ) ;
@@ -236,10 +236,17 @@ Selectize.prototype.onKeyPress = function(e) {
236
236
* @returns {boolean }
237
237
*/
238
238
Selectize . prototype . onKeyDown = function ( e ) {
239
- if ( this . isLocked ) return ;
239
+ var keyCode = e . keyCode || e . which ;
240
240
var isInput = e . target === this . $control_input [ 0 ] ;
241
241
242
- switch ( e . keyCode || e . which ) {
242
+ if ( this . isLocked ) {
243
+ if ( keyCode !== KEY_TAB ) {
244
+ e . preventDefault ( ) ;
245
+ }
246
+ return ;
247
+ }
248
+
249
+ switch ( keyCode ) {
243
250
case KEY_ESC :
244
251
this . blur ( ) ;
245
252
return ;
@@ -299,7 +306,7 @@ Selectize.prototype.onKeyDown = function(e) {
299
306
* @returns {boolean }
300
307
*/
301
308
Selectize . prototype . onKeyUp = function ( e ) {
302
- if ( this . isLocked ) return ;
309
+ if ( this . isLocked ) return e && e . preventDefault ( ) ;
303
310
var value = this . $control_input . val ( ) || '' ;
304
311
if ( this . lastValue !== value ) {
305
312
this . lastValue = value ;
@@ -1108,7 +1115,6 @@ Selectize.prototype.createItem = function() {
1108
1115
var caret = this . caretPos ;
1109
1116
if ( ! input . length ) return ;
1110
1117
this . lock ( ) ;
1111
- this . close ( ) ;
1112
1118
1113
1119
var setup = ( typeof this . settings . create === 'function' ) ? this . settings . create : function ( input ) {
1114
1120
var data = { } ;
@@ -1159,9 +1165,11 @@ Selectize.prototype.refreshItems = function() {
1159
1165
*/
1160
1166
Selectize . prototype . refreshClasses = function ( ) {
1161
1167
var isFull = this . isFull ( ) ;
1168
+ var isLocked = this . isLocked ;
1169
+ this . $control . toggleClass ( 'locked' , isLocked ) ;
1162
1170
this . $control . toggleClass ( 'full' , isFull ) . toggleClass ( 'not-full' , ! isFull ) ;
1163
1171
this . $control . toggleClass ( 'has-items' , this . items . length > 0 ) ;
1164
- this . $control_input . data ( 'grow' , ! isFull ) ;
1172
+ this . $control_input . data ( 'grow' , ! isFull && ! isLocked ) ;
1165
1173
} ;
1166
1174
1167
1175
/**
@@ -1221,7 +1229,7 @@ Selectize.prototype.updatePlaceholder = function() {
1221
1229
* the available options.
1222
1230
*/
1223
1231
Selectize . prototype . open = function ( ) {
1224
- if ( this . isOpen || ( this . settings . mode === 'multi' && this . isFull ( ) ) ) return ;
1232
+ if ( this . isLocked || this . isOpen || ( this . settings . mode === 'multi' && this . isFull ( ) ) ) return ;
1225
1233
this . isOpen = true ;
1226
1234
this . positionDropdown ( ) ;
1227
1235
this . $control . addClass ( 'dropdown-active' ) ;
@@ -1414,16 +1422,17 @@ Selectize.prototype.setCaret = function(i, focus) {
1414
1422
* items are being asynchronously created.
1415
1423
*/
1416
1424
Selectize . prototype . lock = function ( ) {
1425
+ this . close ( ) ;
1417
1426
this . isLocked = true ;
1418
- this . $control . addClass ( 'locked' ) ;
1427
+ this . refreshClasses ( ) ;
1419
1428
} ;
1420
1429
1421
1430
/**
1422
1431
* Re-enables user input on the control.
1423
1432
*/
1424
1433
Selectize . prototype . unlock = function ( ) {
1425
1434
this . isLocked = false ;
1426
- this . $control . removeClass ( 'locked' ) ;
1435
+ this . refreshClasses ( ) ;
1427
1436
} ;
1428
1437
1429
1438
/**
0 commit comments