From 1103e650ff1f804705a7ba41aa21e99d316e9501 Mon Sep 17 00:00:00 2001 From: dburucu Date: Mon, 5 Jan 2015 14:36:29 +0100 Subject: [PATCH] Issue #155 you can set Option "newOptionsAllowed" to accept new options not in select-options. Default is true. --- js/bootstrap-combobox.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-combobox.js b/js/bootstrap-combobox.js index af5dc0d..c094112 100755 --- a/js/bootstrap-combobox.js +++ b/js/bootstrap-combobox.js @@ -35,6 +35,7 @@ this.matcher = this.options.matcher || this.matcher; this.sorter = this.options.sorter || this.sorter; this.highlighter = this.options.highlighter || this.highlighter; + this.newOptionsAllowed = this.options.newOptionsAllowed; this.shown = false; this.selected = false; this.refresh(); @@ -389,11 +390,16 @@ var that = this; this.focused = false; var val = this.$element.val(); - if (!this.selected && val !== '' ) { - this.$element.val(''); - this.$source.val('').trigger('change'); - this.$target.val('').trigger('change'); + if (this.newOptionsAllowed) { + this.$target.val(val); + } else { + if (!this.selected && val !== '' ) { + this.$element.val(''); + this.$source.val('').trigger('change'); + this.$target.val('').trigger('change'); + } } + if (!this.mousedover && this.shown) {setTimeout(function () { that.hide(); }, 200);} } @@ -431,6 +437,7 @@ bsVersion: '3' , menu: '' , item: '
  • ' + , newOptionsAllowed: true }; $.fn.combobox.Constructor = Combobox;