I am using this below form:
<form name="signupForm" id="register-form" ng-submit="addUser(user)" method="POST">
<div class="row">
<input type="email" ng-model="user.email" id="reg_email" class="form-control" placeholder="Email" required pattern="[^@\s]+@[^@\s]+\.[^@\s]+" minlength="5" maxlength="40" required>
<input type="password" ng-model="user.password" id="reg_password" class="form-control" placeholder="Password" required='true' minlength="3" maxlength="10" required>
<input type="submit" id="reg_submit" class="submit-input grad-btn ln-tr" value="Submit">
</div>
</form>
When there error in form, I'm setting setCustomValidity() on input.
auth.signup($scope.userData, successAuth, function (error) {
$rootScope.error = error.error;
console.log("error: " , $rootScope.error);
if($rootScope.error == "user already exists"){
var input = document.getElementById("reg_email");
input.setCustomValidity("$rootScope.error");
} else{
var input = document.getElementById("reg_email");
input.setCustomValidity("");
angular.element('#register-modal').modal('hide');
document.getElementById("register-form").reset();
}
});
Well the modal form doesn't close because of setCustomValidity() but I can't the error message I set on the input field.
Update:
Actually it is showing the error message on second click. why?
Error messages activates on second click and even when form is valid it is showing the error message.