tom-select

Activate the 'add' option by default in Tom Select


I've enabled the "add" option on a Tom Select, which appears at the top of the dropdown when typing in a filter term. Eg:

new TomSelect(target, {
  create: true
});

However, the closest matching option is selected (see pictured). I'd like the "add" option to be selected (highlighted/activated) by default. Is this possible?

tom-select with second option highlighted

I've figured out how to listen to the 'type' event, which happens each time you type into the filter input, but am not sure how to select the "add" option.


Solution

  • Please try setting addPrecedence to true.

    new TomSelect(target, {
      create: true,
      addPrecedence: true
    });
    

    Related documentation.