Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable "remove on backspace" (or remove ibeam entirely)

I'm trying to make a custom select box using selectize.js. So far it was easy to configure and the API supports about everything. The last thing I need to do is disable the option to remove items pressing backspace. For this I couldn't find any methods to call of properties to configure. Do you have any idea on how to achieve this?

Also, another thing that would work for me will be to disable "ibeam". This is the feature that allows you to use the arrow keys to navigate between the selected items. Is this is disabled the user will be able to remove only the last item which is not a big issue for me.

The perfect solution is to disable both, but disabling one of them will work too.

Thanks

like image 991
Andrei Canta Avatar asked Feb 05 '14 16:02

Andrei Canta


4 Answers

A little late to the game...

I wanted to stop backspace from removing items but keep the functionality of the remove buttons.

I wrote this plugin:

Selectize.define("stop_backspace_delete", function (options) {
  var self = this;

  this.deleteSelection = (function() {
    var original = self.deleteSelection;

    return function (e) {
      if (!e || e.keyCode !== 8) {
        return original.apply(this, arguments);
      }

      return false;
    };
  })();
});
like image 77
SwishWez Avatar answered Nov 09 '22 10:11

SwishWez


I've added 3 new config options, submitted them to github and also made a PR.

  1. disableDelete: disable "delete on backspace"
  2. disableCaret: disable moving between items
  3. hidePlaceholder: hide the place holder when there is at least one item selected

Until the PR is accepted here is my repo: https://github.com/deiucanta/selectize.js

like image 41
Andrei Canta Avatar answered Nov 09 '22 12:11

Andrei Canta


I just created a Selectize plugin that removes the ability for the user to deselect options. It completely prevents removing items via backspace or delete buttons.

https://github.com/akrikos/selectize-no-delete

You'll need to include the js file and add the plugin to your selectize options:

$('#selectElement').selectize({
  plugins: {
    'no-delete': {}
  }
});
like image 28
Akrikos Avatar answered Nov 09 '22 12:11

Akrikos


I don't know about earlier version.

But now you can just add in configuration.

persist: true.
like image 1
KumarHarsh Avatar answered Nov 09 '22 12:11

KumarHarsh