Skip to content

Commit

Permalink
Merge pull request #101 from mysmallidea/master
Browse files Browse the repository at this point in the history
Added "addItem" option
  • Loading branch information
bassjobsen committed Dec 18, 2014
2 parents 704eced + 4ba3546 commit d5d71f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap
<td>Adds a delay between lookups.</td>
</tr>
<tr>
<tr>
<td>addItem</td>
<td>JSON object</td>
<td>false</td>
<td>Adds an item to the end of the list, for example "New Entry". This could be used, for example, to pop a dialog when an item is not found in the list of data. Example: <a href="http://cl.ly/image/2u170I1q1G3A/addItem.png">http://cl.ly/image/2u170I1q1G3A/addItem.png</a></td>
</tbody>
</table>

Expand Down
9 changes: 8 additions & 1 deletion bootstrap3-typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
this.listen();
this.showHintOnFocus = typeof this.options.showHintOnFocus == 'boolean' ? this.options.showHintOnFocus : false;
this.afterSelect = this.options.afterSelect;
this.addItem = false;
};

Typeahead.prototype = {
Expand Down Expand Up @@ -151,7 +152,7 @@

items = this.sorter(items);

if (!items.length) {
if (!items.length && !this.options.addItem) {
return this.shown ? this.hide() : this;
}

Expand All @@ -160,6 +161,11 @@
} else {
this.$element.data('active', null);
}

// Add item
if (this.options.addItem){
items.push(this.options.addItem);
}

if (this.options.items == 'all') {
return this.render(items).show();
Expand Down Expand Up @@ -442,6 +448,7 @@
, scrollHeight: 0
, autoSelect: true
, afterSelect: $.noop
, addItem: false
, delay: 0
};

Expand Down
2 changes: 1 addition & 1 deletion bootstrap3-typeahead.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5d71f2

Please sign in to comment.