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

Commit

Permalink
Enhancement #13 - Display errors on Submit
Browse files Browse the repository at this point in the history
- Can now also display all errors on a Submit
- Minified script is now englobed under 1 and only 1 file
(angular-validation.min.js)
  • Loading branch information
ghiscoding committed Mar 29, 2015
1 parent 089dbc0 commit 18765a8
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 338 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#################
## NPM Package
#################
node_modules/

#################
## Eclipse
#################
Expand Down
45 changes: 31 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,53 @@ myApp.config(['$compileProvider', '$locationProvider', '$routeProvider', functio
$routeProvider
.when('/validate-directive', {
templateUrl: 'templates/testingFormDirective.html',
controller: 'Ctrl'
controller: 'CtrlValidationDirective'
})
.when('/validate-service', {
templateUrl: 'templates/testingFormService.html',
controller: 'CtrlValidationService'
})
.otherwise({
redirectTo: 'validate-directive',
});
});
}])
.config(['$translateProvider', function ($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: 'locales/validation/',
suffix: '.json'
});

// load English ('en') table on startup
$translateProvider.preferredLanguage('en');
}]);

// -- Main Controller for Angular-Validation Directive
// -- Main page Controller
// ---------------------------------------------------
myApp.controller('Ctrl', ['$location', '$route', '$scope', '$translate', function ($location, $route, $scope, $translate) {
// change the translation language & reload the page to make sure all errors were rendered properly
$scope.switchLanguage = function (key) {
$scope.switchLanguage = function (key) {
$translate.use(key).then(function() {
$route.reload();
});
});
};
$scope.goto = function ( path ) {
$location.path( path );
};
}]);

// -- Controller to use Angular-Validation Directive
// -----------------------------------------------
myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', function ($scope, validationService) {
$scope.submitForm = function() {
if(new validationService().checkFormValidity($scope.form1)) {
alert('All good, proceed with submit...');
}
}
$scope.showValidationSummary = function () {
$scope.displayValidationSummary = true;
}
}
}]);


// -- Controller to use Angular-Validation Service
// -----------------------------------------------

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

// you can create indepent call to the validation service
// you can create indepent call to the validation service
myValidation.addValidator({
elmName: 'input2',
debounce: 3000,
Expand All @@ -67,7 +76,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
// #1 .addValidtor('myElementName', 'myRules') ... #2 .addValidator({ elmName: 'inputX', rules: 'myRules'})
// the available object properties are the exact same set as the directive except that they are camelCase
myValidation
.setGlobalOptions({ debounce: 1500, scope: $scope })
.setGlobalOptions({ debounce: 1500, scope: $scope })
.addValidator('input3', 'float_signed|between_num:-0.6,99.5|required')
.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')
.addValidator('input5', 'email|required|min_len:6')
Expand All @@ -88,11 +97,19 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
.addValidator('input19', 'date_us_short_between:11/28/99,12/31/15|required')
.addValidator('area1', 'alpha_dash_spaces|min_len:15|required');


// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
$scope.removeInputValidator = function ( elmName ) {
// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
myValidation.removeValidator(elmName);

myValidation.removeValidator(elmName);
$scope.enableRemoveInputValidatorButton = false;
};

$scope.showValidationSummary = function () {
$scope.displayValidationSummary = true;
}

$scope.submitForm = function() {
if(myValidation.checkFormValidity($scope.form1)) {
alert('All good, proceed with submit...');
}
}
}]);
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghiscoding.angular-validation",
"version": "1.3.9",
"version": "1.3.10",
"authors": [
"Ghislain B."
],
Expand Down
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Angular-Validation change logs
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.
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.
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)
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.
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.
1.3.10 (2015-03-28); Added new function of `checkFormValidity()` before submitting the form. Now use only 1 minified script instead of multiples.

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions dist/validation-common.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/validation-directive.min.js

This file was deleted.

Loading

0 comments on commit 18765a8

Please sign in to comment.