-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functionality for form errors thorough angular events.
- Loading branch information
Showing
6 changed files
with
221 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "angular-form-errors", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/blooderking/angular-form-errors.git", | ||
"authors": [ | ||
"Cameron Spear <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
var app = angular.module('app', ['FormErrors']); | ||
|
||
app.config(function (FormErrorsOptionsProvider) { | ||
FormErrorsOptionsProvider.extendDefaultErrorMessages({ | ||
// It only overrides what you pass it. All | ||
// other default messages will be left alone | ||
form: 'has some errors. Please fix them.' | ||
}); | ||
FormErrorsOptionsProvider.extendDefaultErrorMessages({ | ||
// It only overrides what you pass it. All | ||
// other default messages will be left alone | ||
form: 'has some errors. Please fix them.' | ||
}); | ||
}); | ||
|
||
app.controller('MainCtrl', function ($scope) { | ||
$scope.emitErrors = true; | ||
$scope.emitErrors = true; | ||
$scope.errors = {}; | ||
$scope.showChildren = false; | ||
|
||
$scope.errorMessages = { | ||
required: 'é necessário.', | ||
minlength: 'é demasiado curto.', | ||
}; | ||
$scope.errorMessages = { | ||
required: 'é necessário.', | ||
minlength: 'é demasiado curto.', | ||
}; | ||
|
||
$scope.submit = function () { | ||
if ($scope.loginForm.$valid) { | ||
$scope.emitErrors = false; | ||
$scope.message = 'Form is valid!'; | ||
} else { | ||
$scope.emitErrors = true; | ||
$scope.message = 'Please correct the above errors.'; | ||
} | ||
}; | ||
$scope.$on('FORM_ERRORS', function (event, data) { | ||
if (data.errors !== []) | ||
$scope.errors[data.formName] = data.errors; | ||
else | ||
delete $scope.errors[data.formName]; | ||
}); | ||
|
||
$scope.submit = function () { | ||
if ($scope.loginForm.$valid) { | ||
$scope.emitErrors = false; | ||
$scope.message = 'Form is valid!'; | ||
} else { | ||
$scope.emitErrors = true; | ||
$scope.message = 'Please correct the above errors.'; | ||
} | ||
}; | ||
}); |
Oops, something went wrong.