Don't show new contact unless input may be a phone number

This commit is contained in:
lilia 2015-01-25 15:53:12 -10:00
parent 4ee4872b27
commit 5762724709

View file

@ -61,17 +61,27 @@ var Whisper = Whisper || {};
model: new Whisper.Conversation({ model: new Whisper.Conversation({
active_at: null active_at: null
}) })
}).render(); });
this.new_contact.render().$el.hide();
this.$el.find('.new-contact').append(this.new_contact.el); this.$el.find('.new-contact').append(this.new_contact.el);
}, },
filterContacts: function(query) { filterContacts: function(query) {
this.new_contact.model.set('name', query); if (this.maybeNumber(query)) {
this.new_contact.model.set('name', query);
this.new_contact.$el.show();
} else {
this.new_contact.$el.hide();
}
if (query.length) { if (query.length) {
this.typeahead_view.collection.reset( this.typeahead_view.collection.reset(
this.typeahead_collection.typeahead(query) this.typeahead_collection.typeahead(query)
); );
} }
},
maybeNumber: function(number) {
return number.match(/^\+?[0-9]*$/);
} }
}); });