Having issues with the form.$valid
property in my SignUp controller for user registration. It seems to be stuck at false when a validation error is thrown by Sequelize. Any suggestions on what I should modify in my controller? Perhaps resetting the $valid value for a specific input on an ng-change event could help, but I'm not sure how to implement this...
class SignupController {
//start-non-standard
user = {};
errors = {};
submitted = false;
//end-non-standard
constructor(Auth, $state) {
this.Auth = Auth;
this.$state = $state;
}
register(form) {
this.submitted = true;
console.log(this.errors);
if (form.$valid) {
console.log("click");
this.Auth.createUser({
nickname: this.user.nickname,
email: this.user.email,
password: this.user.password
})
.then(() => {
// Account created, redirect to home
this.$state.go('main');
})
.catch(err => {
err = err.data;
this.errors = {};
// Update validity of form fields that match the sequelize errors
if (err.name) {
angular.forEach(err.fields, function(value, key) {
form[key].$setValidity('sequelize', false);
this.errors[key] = err.message;
}, this);
}
});
}
}
}
angular.module('batnApp')
.controller('SignupController', SignupController);