Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

added .trim() to remove surrounding whitespace #734

Merged
merged 3 commits into from
Oct 21, 2014
Merged
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
6 changes: 3 additions & 3 deletions js/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
doSelect: function($item){
if (typeof $item[0] !== 'undefined') {
this.$selectedItem = $item;
this.$input.val(this.$selectedItem.text());
this.$input.val(this.$selectedItem.text().trim());
}
else {
this.$selectedItem = null;
Expand All @@ -91,7 +91,7 @@
var data = {};

if (item) {
var txt = this.$selectedItem.text();
var txt = this.$selectedItem.text().trim();
data = $.extend({ text: txt }, this.$selectedItem.data());
}
else {
Expand Down Expand Up @@ -156,7 +156,7 @@
this.$selectedItem = $(e.target).parent();

// set input text and trigger input change event marked as synthetic
this.$input.val(this.$selectedItem.text()).trigger('change', { synthetic: true });
this.$input.val(this.$selectedItem.text().trim()).trigger('change', { synthetic: true });

// pass object including text and any data-attributes
// to onchange event
Expand Down
8 changes: 8 additions & 0 deletions test/combobox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,12 @@ define(function(require){
equal( $(html).find(id).length, false, 'control has been removed from DOM');
});

test("should remove whitespace", function () {
var $combobox = $(html).find("#MyComboboxWithWhiteSpace").combobox();
$combobox.combobox('selectByIndex', 0);

var item = $combobox.combobox('selectedItem');
equal(item.text, 'no whitespace', 'whitespace was removed');
});

});
23 changes: 23 additions & 0 deletions test/markup/combobox-markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,27 @@
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="MyComboBoxInput">No selected item</label>
<div class="col-sm-10">

<div id="MyComboboxWithWhiteSpace" class="input-group input-append dropdown combobox">
<input id="MyComboBoxWSInput" type="text" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right" aria-hidden="true" role="menu">
<li>
<a href="#">
no whitespace
</a>
</li>
</ul>
</div>
</div>

</div>
</div>
</div>