Skip to content

Commit

Permalink
Added "createOnBlur" option.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Nov 14, 2013
1 parent 854d518 commit 0b7af59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h2>&lt;input type="text"&gt;</h2>
$('#input-tags').selectize({
delimiter: ',',
persist: false,
createOnBlur: true,
create: function(input) {
return {
value: input,
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Selectize.defaults = {
persist: true,
diacritics: true,
create: false,
createOnBlur: false,
highlight: true,
openOnFocus: true,
maxOptions: 1000,
Expand Down
13 changes: 10 additions & 3 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ $.extend(Selectize.prototype, {
self.advanceSelection(1, e);
return;
case KEY_TAB:
if (self.settings.create && $.trim(self.$control_input.val()).length) {
self.createItem();
if (self.settings.create && self.createItem()) {
e.preventDefault();
}
return;
Expand Down Expand Up @@ -520,6 +519,10 @@ $.extend(Selectize.prototype, {
self.isFocused = false;
if (self.ignoreFocus) return;

if (self.settings.create && self.settings.createOnBlur) {
self.createItem();
}

self.close();
self.setTextboxValue('');
self.setActiveItem(null);
Expand Down Expand Up @@ -1312,12 +1315,14 @@ $.extend(Selectize.prototype, {
*
* Once this completes, it will be added
* to the item list.
*
* @return {boolean}
*/
createItem: function() {
var self = this;
var input = $.trim(self.$control_input.val() || '');
var caret = self.caretPos;
if (!input.length) return;
if (!input.length) return false;
self.lock();

var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
Expand Down Expand Up @@ -1345,6 +1350,8 @@ $.extend(Selectize.prototype, {
if (typeof output !== 'undefined') {
create(output);
}

return true;
},

/**
Expand Down

0 comments on commit 0b7af59

Please sign in to comment.