Skip to content

When selectize is disabled the onFocus event fires a blur event which resets focus to the document #583

Closed
@barretts

Description

@barretts

In the onFocus function of selectize.js the blur function is called if the selectize control isDisabled variabled is true. This becomes a problem when you place a selectized element in a form. When you tab to a disabled selectize element the blur is called and moves the users focus to the document start, taking them out of the form they were filling in. This action prevents the user from being able to tab to the next element in the form.

if (self.isDisabled) {
  self.blur();
  e && e.preventDefault();
  return false;
}

I've made a plugin to circumvent this behavior but I thought it might be unintended as it breaks normal the normal flow of forms.

selectize.define('keep_focus_when_disabled', function() {
  var self = this;

  self.onFocus = (function() {
    var original = self.onFocus;
    return function(e) {
      if (self.isDisabled) {
        self.isFocused = true;
        return;
      }
      original.apply(self, arguments);
    };
  })();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions