1

Easiest question ever, I looked at the documentation but can't find the answer. Is there an option to disable the ability to search when clicking the select?

Thanks!

3 Answers3

3

as I'm not allowed to add a comment here is the answer:

https://tom-select.js.org/docs/#controlinput

when you set controlInput: null the search input will disappear.

Hope this helps someone else.

  • Either this changed or it was always only working by accident, it doesn't seem to be documented behavior. Using TS, you cannot even set `null` as a value, it only allows `string|HTMLInputElement` and looking at the code there is now no way you can unset the input. Correct me if I'm wrong. – marc82ch Jul 17 '23 at 20:09
0

I am not sure but if you set search field to null the search will not work any more.

var control = new TomSelect('#select-tools',{
    maxItems: null,
    valueField: 'id',
    labelField: 'title',
    searchField: null, //<------------ HERE
    options: [
        {id: 1, title: 'Spectrometer', url: 'http://en.wikipedia.org/wiki/Spectrometers'},
        {id: 2, title: 'Star Chart', url: 'http://en.wikipedia.org/wiki/Star_chart'},
        {id: 3, title: 'Electrical Tape', url: 'http://en.wikipedia.org/wiki/Electrical_tape'}
    ],
    create: false
});
Suhail
  • 371
  • 2
  • 10
0

The benefit of using the plugin no_backspace_delete from https://tom-select.js.org/plugins/no-backspace-delete and change the dropdownParent to another <select> element that is display: none;

And disable on delete

...
onDelete: function(element) {
    return false;
}
...

And finally make sure create would be false

var control = new TomSelect('#select-tools',{
    maxItems: null,
    valueField: 'id',
    labelField: 'title',
    options: [
        {id: 1, title: 'Spectrometer', url: 'http://en.wikipedia.org/wiki/Spectrometers'},
        {id: 2, title: 'Star Chart', url: 'http://en.wikipedia.org/wiki/Star_chart'},
        {id: 3, title: 'Electrical Tape', url: 'http://en.wikipedia.org/wiki/Electrical_tape'}
    ],
    create: false, // Make sur this is false
    items: [1, 2], // The element that has been selected
    onDelete: function(data) {
      return false; // Disable remove element.
    },
    plugins: ['no_active_items'], // Activate no active items
    dropdownParent: '#parent-select-tools', // The parent select that is hidden.
});
#parent-select-tools{
  display: none;
 }
<script src="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/js/tom-select.complete.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/tom-select@2.2.2/dist/css/tom-select.css" rel="stylesheet"/>

<label for="select-tools">Select items</label>
<select id="select-tools" ></select>


<select id="parent-select-tools"></select>
Pascal Tovohery
  • 888
  • 7
  • 19