(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="subscribe.searchText"
|
||||||
ng-model-options="subscribe.searchTextOptions"
|
ng-model-options="subscribe.searchTextOptions"
|
||||||
var:minlength="minimumSearchLength"
|
var:minlength="minimumSearchLength"
|
||||||
ng-change="subscribe.onChange()"/>
|
ng-change="subscribe.onChange(searchForm.userSearch)"/>
|
||||||
<div ng-messages="searchForm.userSearch.$error">
|
<div ng-messages="searchForm.userSearch.$error">
|
||||||
<div ng-message="minlength"><var:string value="minimumSearchLengthLabel"/></div>
|
<div ng-message="minlength"><var:string value="minimumSearchLengthLabel"/></div>
|
||||||
|
<div ng-message="matches">{{'No such user.' | loc }}</div>
|
||||||
</div>
|
</div>
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -65,8 +65,12 @@
|
||||||
return this.uid == data.uid;
|
return this.uid == data.uid;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options && options.dry)
|
if (options) {
|
||||||
users = [];
|
if (options.dry)
|
||||||
|
users = [];
|
||||||
|
else if (options.results)
|
||||||
|
users = options.results;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
users = User.$users;
|
users = User.$users;
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
vm.selectedUser = null;
|
vm.selectedUser = null;
|
||||||
vm.users = User.$users;
|
vm.users = [];
|
||||||
|
|
||||||
vm.searchTextOptions = {
|
vm.searchTextOptions = {
|
||||||
updateOn: 'default blur',
|
updateOn: 'default blur',
|
||||||
|
@ -74,11 +74,13 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
vm.onChange = function() {
|
vm.onChange = function(input) {
|
||||||
User.$filter(vm.searchText).then(function() {
|
User.$filter(vm.searchText, null, { results: vm.users }).then(function(users) {
|
||||||
|
input.$setValidity('matches', users.length > 0);
|
||||||
|
input.$setTouched();
|
||||||
if (vm.selectedUser) {
|
if (vm.selectedUser) {
|
||||||
// If selected user is no longer part of the matching users, unselect it
|
// 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;
|
return user.uid == vm.selectedUser.uid;
|
||||||
}))) {
|
}))) {
|
||||||
vm.selectedUser = null;
|
vm.selectedUser = null;
|
||||||
|
|
Loading…
Reference in a new issue