Skip to content

Commit c67e203

Browse files
committed
Set hidden field value if preselected, version 1.1.4
1 parent 0421f16 commit c67e203

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

js/bootstrap-combobox.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* =============================================================
2-
* bootstrap-combobox.js v1.1.3
2+
* bootstrap-combobox.js v1.1.4
33
* =============================================================
44
* Copyright 2012 Daniel Farrell
55
*
@@ -57,6 +57,7 @@
5757
, map = {}
5858
, source = []
5959
, selected = false
60+
, selectedValue = ''
6061
this.$source.find('option').each(function() {
6162
var option = $(this)
6263
if (option.val() === '') {
@@ -65,11 +66,15 @@
6566
}
6667
map[option.text()] = option.val()
6768
source.push(option.text())
68-
if(option.attr('selected')) selected = option.text()
69+
if (option.attr('selected')) {
70+
selected = option.text()
71+
selectedValue = option.val()
72+
}
6973
})
7074
this.map = map
7175
if (selected) {
7276
this.$element.val(selected)
77+
this.$target.val(selectedValue)
7378
this.$container.addClass('combobox-selected')
7479
this.selected = true
7580
}

js/tests/unit/bootstrap-combobox.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ $(function () {
214214
test("should set as selected if select was selected before load", function () {
215215
var $select = $('<select><option></option><option>aa</option><option selected>ab</option><option>ac</option></select>')
216216
, $input = $select.combobox().data('combobox').$element
217+
, $target = $select.combobox().data('combobox').$target
217218
, combobox = $select.data('combobox')
218219

219220
equal($input.val(), 'ab', 'input value was correctly set')
221+
equal($target.val(), 'ab', 'hidden input value was correctly set')
220222
equal($select.val(), 'ab', 'select value was correctly set')
221223
})
222224

0 commit comments

Comments
 (0)