As the title, on selectize, how can I disabled typing except Backspace key.
It will be allowed to:
- Select item on dropdown.
- Delete selected items.
It will NOT be allowed to:
- Type or add any new items.
I have read the API document but I can't found the solution. Any suggestions.
Here mine:
var $select = $('#tags').selectize({
maxItems: 5,
persist: false,
createOnBlur: true,
create: true,
});
UPDATE:
I found the solution by my own
$select[0].selectize.$control_input.on('keydown', function(e) {
var key = e.charCode || e.keyCode;
if(key == 8 )
return true;
else
e.preventDefault();
});
As the title, on selectize, how can I disabled typing except Backspace key.
It will be allowed to:
- Select item on dropdown.
- Delete selected items.
It will NOT be allowed to:
- Type or add any new items.
I have read the API document but I can't found the solution. Any suggestions.
Here mine:
var $select = $('#tags').selectize({
maxItems: 5,
persist: false,
createOnBlur: true,
create: true,
});
UPDATE:
I found the solution by my own
$select[0].selectize.$control_input.on('keydown', function(e) {
var key = e.charCode || e.keyCode;
if(key == 8 )
return true;
else
e.preventDefault();
});
Share
Improve this question
edited Oct 5, 2016 at 6:30
TommyDo
asked Oct 5, 2016 at 5:02
TommyDoTommyDo
6738 silver badges25 bronze badges
1
- The solutions listed above didn't work But this is work! stackoverflow./a/30087408/20175904 – Evgenii St. Commented Oct 7, 2022 at 9:37
1 Answer
Reset to default 5While the way you did it works, the proper way to prevent item addition is to use create: false
:
var $select = $('#tags').selectize({
maxItems: 5,
persist: false,
create: false
});