Be more clever about whitespace in typeahead for adding subscribers

* Ignore beginning and ending whitespace when submitting the form
* Ignore beginning and ending whitespace when doing autocomplete
* Don't autocomplete on just whitespace

(imported from commit b3231e08f6797a38bafbcef2e694f4bae059c20f)
This commit is contained in:
Zev Benjamin 2013-01-10 14:10:06 -05:00
parent cd60f18752
commit 3442ac05b8
1 changed files with 9 additions and 1 deletions

View File

@ -307,7 +307,7 @@ $(function () {
var sub_row = $(e.target).closest('.subscription_row');
var stream = sub_row.find('.subscription_name').text();
var text_box = sub_row.find('input[name="principal"]');
var principal = text_box.val();
var principal = $.trim(text_box.val());
// TODO: clean up this error handling
var error_elem = sub_row.find('.subscriber_list_container .alert-error');
var warning_elem = sub_row.find('.subscriber_list_container .alert-warning');
@ -368,6 +368,14 @@ $(function () {
var query = this.query;
return typeahead_helper.highlight_with_escaping(query, item);
},
matcher: function (item) {
var query = $.trim(this.query);
if (query === '') {
return false;
}
// Case-insensitive.
return (item.toLowerCase().indexOf(query.toLowerCase()) !== -1);
},
updater: function (item) {
return typeahead_helper.private_message_mapped[item].email;
}