Skip to content

Commit

Permalink
Allow setting a placeholder from data attribute
Browse files Browse the repository at this point in the history
Use data-placeholder="" on the select

fixes danielfarrell#12
  • Loading branch information
Daniel Farrell committed Apr 20, 2012
1 parent df3a3d3 commit 9617675
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/bootstrap-combobox.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
this.sorter = this.options.sorter || this.sorter this.sorter = this.options.sorter || this.sorter
this.highlighter = this.options.highlighter || this.highlighter this.highlighter = this.options.highlighter || this.highlighter
this.$menu = $(this.options.menu).appendTo('body') this.$menu = $(this.options.menu).appendTo('body')
this.placeholder = this.options.placeholder || this.placeholder this.placeholder = this.options.placeholder || this.$target.attr('data-placeholder')
this.$element.attr('placeholder', this.placeholder) this.$element.attr('placeholder', this.placeholder)
this.shown = false this.shown = false
this.refresh() this.refresh()
Expand Down
8 changes: 8 additions & 0 deletions js/tests/unit/bootstrap-combobox.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ $(function () {


equals($input.attr('placeholder'), 'Type something...', 'input value was correctly set') equals($input.attr('placeholder'), 'Type something...', 'input value was correctly set')
}) })

test("should set placeholder text on the input if specified as an data attribute", function() {
var $select = $('<select data-placeholder="Type something..."><option></option><option>aa</option><option selected>ab</option><option>ac</option></select>')
, $input = $select.combobox().data('combobox').$element
, combobox = $select.data('combobox')

equals($input.attr('placeholder'), 'Type something...', 'input value was correctly set')
})
}) })

0 comments on commit 9617675

Please sign in to comment.