Disable typing on selectize
Asked Answered
A

1

7

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();
    });
Antepast answered 5/10, 2016 at 5:2 Comment(1)
The solutions listed above didn't work But this is work! https://mcmap.net/q/1625008/-selectize-causes-keyboard-to-appear-on-androidBarde
M
5

While 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
});
Moslem answered 6/10, 2016 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.