Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 18765a8

Browse files
committed
Enhancement #13 - Display errors on Submit
- Can now also display all errors on a Submit - Minified script is now englobed under 1 and only 1 file (angular-validation.min.js)
1 parent 089dbc0 commit 18765a8

22 files changed

+436
-338
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#################
2+
## NPM Package
3+
#################
4+
node_modules/
5+
16
#################
27
## Eclipse
38
#################

app.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,53 @@ myApp.config(['$compileProvider', '$locationProvider', '$routeProvider', functio
77
$routeProvider
88
.when('/validate-directive', {
99
templateUrl: 'templates/testingFormDirective.html',
10-
controller: 'Ctrl'
10+
controller: 'CtrlValidationDirective'
1111
})
1212
.when('/validate-service', {
1313
templateUrl: 'templates/testingFormService.html',
1414
controller: 'CtrlValidationService'
1515
})
1616
.otherwise({
1717
redirectTo: 'validate-directive',
18-
});
18+
});
1919
}])
2020
.config(['$translateProvider', function ($translateProvider) {
2121
$translateProvider.useStaticFilesLoader({
2222
prefix: 'locales/validation/',
2323
suffix: '.json'
2424
});
25-
25+
2626
// load English ('en') table on startup
2727
$translateProvider.preferredLanguage('en');
2828
}]);
2929

30-
// -- Main Controller for Angular-Validation Directive
30+
// -- Main page Controller
3131
// ---------------------------------------------------
3232
myApp.controller('Ctrl', ['$location', '$route', '$scope', '$translate', function ($location, $route, $scope, $translate) {
3333
// change the translation language & reload the page to make sure all errors were rendered properly
34-
$scope.switchLanguage = function (key) {
34+
$scope.switchLanguage = function (key) {
3535
$translate.use(key).then(function() {
3636
$route.reload();
37-
});
37+
});
3838
};
3939
$scope.goto = function ( path ) {
4040
$location.path( path );
4141
};
42+
}]);
43+
44+
// -- Controller to use Angular-Validation Directive
45+
// -----------------------------------------------
46+
myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', function ($scope, validationService) {
47+
$scope.submitForm = function() {
48+
if(new validationService().checkFormValidity($scope.form1)) {
49+
alert('All good, proceed with submit...');
50+
}
51+
}
4252
$scope.showValidationSummary = function () {
4353
$scope.displayValidationSummary = true;
44-
}
54+
}
4555
}]);
4656

47-
4857
// -- Controller to use Angular-Validation Service
4958
// -----------------------------------------------
5059

@@ -53,7 +62,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
5362
// start by creating the service
5463
var myValidation = new validationService();
5564

56-
// you can create indepent call to the validation service
65+
// you can create indepent call to the validation service
5766
myValidation.addValidator({
5867
elmName: 'input2',
5968
debounce: 3000,
@@ -67,7 +76,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
6776
// #1 .addValidtor('myElementName', 'myRules') ... #2 .addValidator({ elmName: 'inputX', rules: 'myRules'})
6877
// the available object properties are the exact same set as the directive except that they are camelCase
6978
myValidation
70-
.setGlobalOptions({ debounce: 1500, scope: $scope })
79+
.setGlobalOptions({ debounce: 1500, scope: $scope })
7180
.addValidator('input3', 'float_signed|between_num:-0.6,99.5|required')
7281
.addValidator('input4', 'exact_len:4|regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex|required|integer')
7382
.addValidator('input5', 'email|required|min_len:6')
@@ -88,11 +97,19 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
8897
.addValidator('input19', 'date_us_short_between:11/28/99,12/31/15|required')
8998
.addValidator('area1', 'alpha_dash_spaces|min_len:15|required');
9099

91-
100+
// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
92101
$scope.removeInputValidator = function ( elmName ) {
93-
// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
94-
myValidation.removeValidator(elmName);
95-
102+
myValidation.removeValidator(elmName);
96103
$scope.enableRemoveInputValidatorButton = false;
97104
};
105+
106+
$scope.showValidationSummary = function () {
107+
$scope.displayValidationSummary = true;
108+
}
109+
110+
$scope.submitForm = function() {
111+
if(myValidation.checkFormValidity($scope.form1)) {
112+
alert('All good, proceed with submit...');
113+
}
114+
}
98115
}]);

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ghiscoding.angular-validation",
3-
"version": "1.3.9",
3+
"version": "1.3.10",
44
"authors": [
55
"Ghislain B."
66
],

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Angular-Validation change logs
1010
1.3.6 (2015-02-09): Added ng-strict-di for minification, renamed some files and folder lib to /vendors, moved directive into new /src folder for better separation.
1111
1.3.7 (2015-03-08): Complete rewrite (but same functionality) so that I could add an Angular-Validation Service which is similar implementation as the Directive. Also added `debounce` attribute which is an alias to `typingLimit`, validation rules are now defined as an external service for better maintainability and also created a common file for shared functions by both Validation Directive and Service.
1212
1.3.8 (2015-03-15): Added between/min/max conditional validators on all Date types (ISO, EURO_LONG, EURO_SHORT, US_LONG, US_SHORT)
13-
1.3.9 (2015-03-21): Added validation summary through 2 new and equivalent properties `$scope.$validationSummary` and `$scope.formName.$validationSummary`. Also added `bower` and `gulp` support, the Gulp script gives minified files.
13+
1.3.9 (2015-03-21): Added validation summary through 2 new and equivalent properties `$scope.$validationSummary` and `$scope.formName.$validationSummary`. Also added `bower` and `gulp` support, the Gulp script gives minified files.
14+
1.3.10 (2015-03-28); Added new function of `checkFormValidity()` before submitting the form. Now use only 1 minified script instead of multiples.

dist/angular-validation-allin1.min.js renamed to dist/angular-validation.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/validation-common.min.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

dist/validation-directive.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)