Skip to content

Commit

Permalink
Add option for html5 placeholder on input
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfuentes2 committed Apr 8, 2012
1 parent cb875d5 commit f47ec28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions js/bootstrap-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
this.sorter = this.options.sorter || this.sorter
this.highlighter = this.options.highlighter || this.highlighter
this.$menu = $(this.options.menu).appendTo('body')
this.placeholder = this.options.placeholder || this.placeholder
this.$element.attr('placeholder', this.placeholder)
this.shown = false
this.refresh()
this.listen()
Expand Down Expand Up @@ -166,6 +168,7 @@
template: '<div class="combobox-container"><input type="text" /><span class="add-on btn dropdown-toggle" data-dropdown="dropdown"><span class="caret"/><span class="combobox-clear"><i class="icon-remove"/></span></span></div>'
, menu: '<ul class="typeahead typeahead-long dropdown-menu"></ul>'
, item: '<li><a href="#"></a></li>'
, placeholder: null
}

$.fn.combobox.Constructor = Combobox
Expand Down
8 changes: 8 additions & 0 deletions js/tests/unit/bootstrap-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,12 @@ $(function () {
equals($input.val(), 'ab', 'input value was correctly set')
equals($select.val(), 'ab', 'select value was correctly set')
})

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

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

0 comments on commit f47ec28

Please sign in to comment.