Validate forms the Angular way. Also: Validate on submit.

This commit is contained in:
Your Name 2014-06-06 18:24:40 +02:00
parent caf732a04c
commit 2a0b2add0d
9 changed files with 51 additions and 43 deletions
app/scripts/directives

View file

@ -2,17 +2,17 @@
angular.module('ffffng')
.directive('fTokenForm', function () {
var ctrl = function ($scope, Constraints, Validator) {
var isValid = Validator.forConstraint(Constraints.token);
$scope.hasError = function () {
var value = $scope.token;
if (value === undefined) {
return false;
}
return !isValid(value);
};
var ctrl = function ($scope, Constraints) {
$scope.constraints = Constraints;
$scope.submitted = false;
$scope.doSubmit = function (token) {
$scope.submitted = true;
if ($scope.tokenForm.$invalid) {
return;
}
$scope.error = null;
$scope.onSubmit(token)
.error(function (response, code) {