Skip to content

Commit 9617675

Browse files
author
Daniel Farrell
committed
Allow setting a placeholder from data attribute
Use data-placeholder="" on the select fixes danielfarrell#12
1 parent df3a3d3 commit 9617675

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

js/bootstrap-combobox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
this.sorter = this.options.sorter || this.sorter
3131
this.highlighter = this.options.highlighter || this.highlighter
3232
this.$menu = $(this.options.menu).appendTo('body')
33-
this.placeholder = this.options.placeholder || this.placeholder
33+
this.placeholder = this.options.placeholder || this.$target.attr('data-placeholder')
3434
this.$element.attr('placeholder', this.placeholder)
3535
this.shown = false
3636
this.refresh()

js/tests/unit/bootstrap-combobox.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,12 @@ $(function () {
220220

221221
equals($input.attr('placeholder'), 'Type something...', 'input value was correctly set')
222222
})
223+
224+
test("should set placeholder text on the input if specified as an data attribute", function() {
225+
var $select = $('<select data-placeholder="Type something..."><option></option><option>aa</option><option selected>ab</option><option>ac</option></select>')
226+
, $input = $select.combobox().data('combobox').$element
227+
, combobox = $select.data('combobox')
228+
229+
equals($input.attr('placeholder'), 'Type something...', 'input value was correctly set')
230+
})
223231
})

0 commit comments

Comments
 (0)