(js) Improve ng-messages of sg-subscribe
Improved dry mode of User.$filter and added error message when users search returns no match.
This commit is contained in:
parent
03ddcfd07a
commit
d92bf122ed
|
@ -27,9 +27,10 @@
|
|||
ng-model="subscribe.searchText"
|
||||
ng-model-options="subscribe.searchTextOptions"
|
||||
var:minlength="minimumSearchLength"
|
||||
ng-change="subscribe.onChange()"/>
|
||||
ng-change="subscribe.onChange(searchForm.userSearch)"/>
|
||||
<div ng-messages="searchForm.userSearch.$error">
|
||||
<div ng-message="minlength"><var:string value="minimumSearchLengthLabel"/></div>
|
||||
<div ng-message="matches">{{'No such user.' | loc }}</div>
|
||||
</div>
|
||||
</md-input-container>
|
||||
</form>
|
||||
|
|
|
@ -65,8 +65,12 @@
|
|||
return this.uid == data.uid;
|
||||
};
|
||||
|
||||
if (options && options.dry)
|
||||
users = [];
|
||||
if (options) {
|
||||
if (options.dry)
|
||||
users = [];
|
||||
else if (options.results)
|
||||
users = options.results;
|
||||
}
|
||||
else
|
||||
users = User.$users;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
var vm = this;
|
||||
|
||||
vm.selectedUser = null;
|
||||
vm.users = User.$users;
|
||||
vm.users = [];
|
||||
|
||||
vm.searchTextOptions = {
|
||||
updateOn: 'default blur',
|
||||
|
@ -74,11 +74,13 @@
|
|||
}
|
||||
};
|
||||
|
||||
vm.onChange = function() {
|
||||
User.$filter(vm.searchText).then(function() {
|
||||
vm.onChange = function(input) {
|
||||
User.$filter(vm.searchText, null, { results: vm.users }).then(function(users) {
|
||||
input.$setValidity('matches', users.length > 0);
|
||||
input.$setTouched();
|
||||
if (vm.selectedUser) {
|
||||
// If selected user is no longer part of the matching users, unselect it
|
||||
if (_.isUndefined(_.find(User.$users, function(user) {
|
||||
if (_.isUndefined(_.find(users, function(user) {
|
||||
return user.uid == vm.selectedUser.uid;
|
||||
}))) {
|
||||
vm.selectedUser = null;
|
||||
|
|
Loading…
Reference in a new issue