Clean up username validation in bonfires and remove red border from input field if user deletes all input

This commit is contained in:
Nathan Leniz
2015-02-14 21:48:48 -05:00
parent 20b37ac470
commit 4f6a6bd8f0
2 changed files with 3 additions and 8 deletions

View File

@ -192,11 +192,9 @@ exports.checkUniqueUsername = function(req, res) {
*/ */
exports.checkExistingUsername = function(req, res) { exports.checkExistingUsername = function(req, res) {
User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) { User.count({'profile.username': req.params.username.toLowerCase()}, function (err, data) {
if (data == 1) { if (data === 1) {
debug('sending false back')
return res.send(true); return res.send(true);
} else { } else {
debug('sending true back')
return res.send(false); return res.send(false);
} }
}); });

View File

@ -194,15 +194,12 @@ profileValidation.directive('existingUsername', function($http) {
if (element.val().length > 0) { if (element.val().length > 0) {
ngModel.$setValidity('exists', false); ngModel.$setValidity('exists', false);
} else { } else {
$('#completed-with').removeClass('ng-dirty');
ngModel.$setPristine(); ngModel.$setPristine();
} }
if (element.val()) { if (element.val()) {
$http.get("/api/checkExistingUsername/" + element.val()).success(function (data) { $http.get("/api/checkExistingUsername/" + element.val()).success(function (data) {
if (element.val() == scope.existingUsername) { ngModel.$setValidity('exists', data);
ngModel.$setValidity('exists', false);
} else if (data) {
ngModel.$setValidity('exists', true);
}
}); });
} }
}); });