diff --git a/js/bootstrap-combobox.js b/js/bootstrap-combobox.js
index c15b768..beaf7dd 100644
--- a/js/bootstrap-combobox.js
+++ b/js/bootstrap-combobox.js
@@ -51,6 +51,8 @@
select.before(combobox)
select.detach()
combobox.append(select)
+ combobox.find('input[type=text]').attr('name', combobox.find('select').attr('name')) // Name the text field to allow for custom-entered choices
+ combobox.find('select').removeAttr('name') // Remove the name from the previous select
return combobox
}
@@ -103,8 +105,6 @@
var val = this.$menu.find('.active').attr('data-value')
this.$element.val(val)
this.$container.addClass('combobox-selected')
- this.$target.val(this.map[val])
- this.$target.trigger('change')
this.selected = true
return this.hide()
}
@@ -186,11 +186,6 @@
var that = this
e.stopPropagation()
e.preventDefault()
- var val = this.$element.val()
- if (!this.selected && val != "" ) {
- this.$element.val("")
- this.$target.val("").trigger('change')
- }
if (this.shown) {
setTimeout(function () { that.hide() }, 150)
}
diff --git a/js/tests/unit/bootstrap-combobox.js b/js/tests/unit/bootstrap-combobox.js
index c3c6af9..aeafd5e 100644
--- a/js/tests/unit/bootstrap-combobox.js
+++ b/js/tests/unit/bootstrap-combobox.js
@@ -122,7 +122,7 @@ $(function () {
})
- test("should set input and select value to selected item", function () {
+ test("should set input to selected item", function () {
var $select = $('')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
@@ -133,7 +133,6 @@ $(function () {
$(combobox.$menu.find('li')[2]).mouseover().click()
equals($input.val(), 'ac', 'input value was correctly set')
- equals($select.val(), 'ac', 'select value was correctly set')
ok(!combobox.$menu.is(':visible'), 'the menu was hidden')
combobox.$menu.remove()
@@ -167,7 +166,7 @@ $(function () {
combobox.$menu.remove()
})
- test("should clear and focus input and select and remove class from container when button is clicked when item is selected", function () {
+ test("should clear and focus input and remove class from container when button is clicked when item is selected", function () {
var $select = $('')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
@@ -178,12 +177,10 @@ $(function () {
$(combobox.$menu.find('li')[2]).mouseover().click()
equals($input.val(), 'ac', 'input value was correctly set')
- equals($select.val(), 'ac', 'select value was correctly set')
combobox.$button.mouseover().click()
equals($input.val(), '', 'input value was cleared correctly')
- equals($select.val(), '', 'select value was cleared correctly')
// ok($input.is(":focus"), 'input has focus')
combobox.$menu.remove()
@@ -198,7 +195,7 @@ $(function () {
equals($select.val(), 'ab', 'select value was correctly set')
})
- test("should clear input on blur when value does not exist", function() {
+ test("should not clear input on blur when value does not exist in select", function() {
var $select = $('')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
@@ -207,8 +204,7 @@ $(function () {
combobox.lookup()
$input.trigger('blur')
- equals($input.val(), '', 'input value was correctly set')
- equals($select.val(), 'aa', 'select value was correctly set')
+ equals($input.val(), 'DOES NOT EXIST', 'input value was correctly set')
combobox.$menu.remove()
})