Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom-entered choices to be used in the combo box #20

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions js/bootstrap-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 4 additions & 8 deletions js/tests/unit/bootstrap-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<select><option></option><option>aa</option><option>ab</option><option>ac</option></select>')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
Expand All @@ -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()
Expand Down Expand Up @@ -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 = $('<select><option></option><option>aa</option><option>ab</option><option>ac</option></select>')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
Expand All @@ -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()
Expand All @@ -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 = $('<select><option>aa</option></select>')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')
Expand All @@ -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()
})
Expand Down