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

Commit 450d4fb

Browse files
committed
Fixed issue #91, enhancements #97 and #98
1 parent fe72fc9 commit 450d4fb

17 files changed

+669
-96
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.4.17",
3+
"version": "1.4.18",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Angular-Validation change logs
22

3+
1.4.18 (2015-12-20) Fixed issue #91 interpolation problem with remove validation doesn't work twice. Enhancement #98 possibility to use one validation or another (tell how many Validators are required for field to become valid). Enhancement #97 possibility to validate even on empty text field (useful on `custom` and `remote` validation). Refined some Validators (IPV6 now include compressed/uncompressed addresses, added more Polish characters to other Validators)
34
1.4.17 (2015-12-15) Fixed issue #92 input name with '.', enhancement #94 Polish characters, issue #96 in_list wasn't accepting special characters.
45
1.4.16 (2015-12-11) Fixed issue #90 blinking error messages.
56
1.4.15 (2015-12-02) Fixed issue #86 implicit global variable on regex.

dist/angular-validation.min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
'use strict';
2+
3+
var myApp = angular.module('emptyCustomValidation', ['ghiscoding.validation', 'pascalprecht.translate',
4+
'emptyCustomValidation.controllers']);
5+
// --
6+
// configuration
7+
myApp.config(['$compileProvider', function ($compileProvider) {
8+
$compileProvider.debugInfoEnabled(false);
9+
}])
10+
.config(['$translateProvider', function ($translateProvider) {
11+
$translateProvider.useStaticFilesLoader({
12+
prefix: '../../locales/validation/',
13+
suffix: '.json'
14+
});
15+
// load English ('en') table on startup
16+
$translateProvider.preferredLanguage('en').fallbackLanguage('en');
17+
$translateProvider.useSanitizeValueStrategy('escapeParameters');
18+
}]);
19+
20+
21+
myApp.run(function ($rootScope) {
22+
$rootScope.$validationOptions = { debounce: 0 };
23+
});
24+
25+
angular.module('emptyCustomValidation.controllers', []).
26+
controller('myController', function($scope, validationService) {
27+
$scope.existingEmployees = [
28+
{
29+
firstName: 'John',
30+
lastName: 'Doe',
31+
id: 1
32+
},
33+
{
34+
firstName: 'Jane',
35+
lastName: 'Doe',
36+
id: 2
37+
}];
38+
$scope.newEmployees = [
39+
{firstName : '', lastName: '', id : -1},
40+
{firstName : '', lastName: '', id : -2},
41+
{firstName : '', lastName: '', id : -3},
42+
{firstName : '', lastName: '', id : -4},
43+
{firstName : '', lastName: '', id : -5}
44+
];
45+
46+
$scope.submit = function() {
47+
if (!new validationService().checkFormValidity($scope.inputForm)) {
48+
var msg = '';
49+
$scope.inputForm.$validationSummary.forEach(function (validationItem) {
50+
msg += validationItem.message + '\n';
51+
});
52+
alert(msg);
53+
return;
54+
}
55+
alert('Data saved successfully.');
56+
};
57+
58+
function employeeHasData(employee)
59+
{
60+
if ((!employee.firstName || employee.firstName === '') && (!employee.lastName || employee.lastName === ''))
61+
return false;
62+
return true;
63+
}
64+
$scope.newEmployeeFirstNameValidation = function(employee) {
65+
//alert('First name validation');
66+
var isValid = true;
67+
var msg = '';
68+
if (employeeHasData(employee) && !employee.firstName)
69+
{
70+
isValid = false;
71+
msg = 'First name required';
72+
}
73+
74+
// The next 4 lines are only here to show that custom validation works if text is given
75+
if (isValid && employee.firstName && employee.firstName.length > 10)
76+
{
77+
isValid = false;
78+
msg = 'Max number of characters for first name: 10'
79+
}
80+
81+
return { isValid: isValid, message: msg };
82+
};
83+
84+
$scope.newEmployeeLastNameValidation = function(employee) {
85+
var isValid = true;
86+
var msg = '';
87+
if (employeeHasData(employee) && !employee.lastName)
88+
{
89+
isValid = false;
90+
msg = 'Last name required';
91+
}
92+
93+
// The next 4 lines are only here to show that custom validation works if text is given
94+
if (isValid && employee.lastName && employee.lastName.length > 8)
95+
{
96+
isValid = false;
97+
msg = 'Max number of characters for last name: 8'
98+
}
99+
return { isValid: isValid, message: msg };
100+
};
101+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Angular-Validation with Custom Javascript function</title>
6+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="../../style.css">
8+
</head>
9+
10+
<body ng-app="emptyCustomValidation" ng-controller="myController">
11+
<div class="container">
12+
<form name="inputForm" ng-submit="submit()">
13+
<h1>Employess in db</h1>
14+
<table>
15+
<tbody>
16+
<tr>
17+
<th>First name</th>
18+
<th>Last name</th>
19+
</tr>
20+
<tr ng-repeat="employee in existingEmployees">
21+
<td>
22+
<input type="text" name="existingEmployee_firstName_{{employee.id}}" ng-model="employee.firstName" validation="required" class="form-control" />
23+
</td>
24+
<td>
25+
<input type="text" name="existingEmployee_lastName_{{employee.id}}" ng-model="employee.lastName" validation="required" class="form-control" />
26+
</td>
27+
</tr>
28+
</tbody>
29+
</table>
30+
<br />
31+
<br />
32+
<br />
33+
<h1>New employees</h1>
34+
<table>
35+
<tbody>
36+
<tr>
37+
<th>First name</th>
38+
<th>Last name</th>
39+
</tr>
40+
<tr ng-repeat="employee in newEmployees">
41+
<td>
42+
<input type="text" name="newEmployee_firstName_{{employee.id}}" ng-model="employee.firstName" validation="custom:newEmployeeFirstNameValidation(employee)" validate-on-empty="true" class="form-control" />
43+
</td>
44+
<td>
45+
<input type="text" name="newEmployee_lastName_{{employee.id}}" ng-model="employee.lastName" validation="custom:newEmployeeLastNameValidation(employee)" class="form-control" />
46+
</td>
47+
</tr>
48+
</tbody>
49+
</table><br /><br /><br />
50+
<button class="btn btn-default">
51+
Submit
52+
</button>
53+
</form>
54+
</div>
55+
56+
<!-- external librairies CDN -->
57+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
58+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.js"></script>
59+
60+
<!-- angular-translate -->
61+
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
62+
<script src="../../vendors/angular-translate/angular-translate.min.js"></script>
63+
<script src="../../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
64+
65+
<!-- Angular-UI -->
66+
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.2.js"></script>
67+
68+
<!-- Angular-Validation -->
69+
<!--<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>-->
70+
71+
<script type="text/javascript" src="../../src/validation-directive.js"></script>
72+
<script type="text/javascript" src="../../src/validation-service.js"></script>
73+
<script type="text/javascript" src="../../src/validation-common.js"></script>
74+
<script type="text/javascript" src="../../src/validation-rules.js"></script>
75+
76+
77+
<!-- my application -->
78+
<script type="text/javascript" src="app.js"></script>
79+
</body>
80+
</html>
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
var myApp = angular.module('myApp', ['ghiscoding.validation', 'pascalprecht.translate', 'ui.bootstrap']);
4+
// --
5+
// configuration
6+
myApp.config(['$compileProvider', function ($compileProvider) {
7+
$compileProvider.debugInfoEnabled(false);
8+
}])
9+
.config(['$translateProvider', function ($translateProvider) {
10+
$translateProvider.useStaticFilesLoader({
11+
prefix: '../../locales/validation/',
12+
suffix: '.json'
13+
});
14+
// load English ('en') table on startup
15+
$translateProvider.preferredLanguage('en').fallbackLanguage('en');
16+
$translateProvider.useSanitizeValueStrategy('escapeParameters');
17+
}]);
18+
19+
// --
20+
// Directive
21+
myApp.controller('CtrlDirective', ['validationService', function (validationService) {
22+
var vmd = this;
23+
vmd.model = {};
24+
25+
// use the validationService only to declare the controllerAs syntax
26+
var vs = new validationService({ controllerAs: vmd });
27+
28+
vmd.submitForm = function() {
29+
if(vs.checkFormValidity(vmd.form1)) {
30+
alert('All good, proceed with submit...');
31+
}
32+
}
33+
}]);
34+
35+
// --
36+
// Service
37+
myApp.controller('CtrlService', ['$scope', 'validationService', function ($scope, validationService) {
38+
var vms = this;
39+
vms.model = {};
40+
41+
// use the validationService only to declare the controllerAs syntax
42+
var vs = new validationService({ controllerAs: vms });
43+
44+
vs.addValidator({
45+
elmName: 'input2',
46+
validRequireHowMany: 2,
47+
scope: $scope,
48+
rules: 'ipv4|ipv6|required'
49+
});
50+
51+
vms.submitForm = function() {
52+
if(new validationService().checkFormValidity(vms.form2)) {
53+
alert('All good, proceed with submit...');
54+
}
55+
}
56+
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE html>
2+
<html ng-app="myApp" ng-strict-di ng-cloak="">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Angular-Validation with ValidRequireHowMany</title>
6+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
7+
<link rel="stylesheet" href="../../style.css">
8+
</head>
9+
10+
<body>
11+
<div class="container">
12+
<h2>Angular-Validation with ValidRequireHowMany</h2>
13+
14+
<div ng-controller="CtrlDirective as vmd">
15+
<h3>Directive</h3>
16+
<div class="alert alert-danger alert-dismissable" ng-show="vmd.form1.$validationSummary.length &gt; 0">
17+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
18+
<h4><strong>ERRORS!</strong></h4>
19+
<ul>
20+
<li ng-repeat="item in vmd.form1.$validationSummary">{{ item.field }}: {{item.message}}</li>
21+
</ul>
22+
</div>
23+
24+
<form name="vmd.form1">
25+
<div class="form-group">
26+
<label for="input1">Validate IPV4 or IPV6 (required + IPV4 or IPV6 --&gt; validRequireHowMany="2")</label>
27+
<input type="text" class="form-control"
28+
name="input1"
29+
ng-model="vmd.model.input1"
30+
placeholder="validation='ipv4|ipv6|required' ... validRequireHowMany='2'"
31+
valid-require-how-many="2"
32+
validation="ipv4|ipv6|required" />
33+
</div>
34+
<br/>
35+
<div class="form-actions">
36+
<button type="submit" name="btn_ngDisabled1" class="btn btn-primary" ng-disabled="vmd.form1.$invalid" >{{ 'SAVE' | translate }} (ngDisabled)</button>
37+
<button type="submit" name="btn_ngSubmit1" class="btn btn-primary" ng-click="vmd.submitForm()">{{ 'SAVE' | translate }} (ngSubmit)</button>
38+
</div>
39+
</form>
40+
</div>
41+
42+
<hr/>
43+
44+
<div ng-controller="CtrlService as vms">
45+
<h3>Service</h3>
46+
<div class="alert alert-danger alert-dismissable" ng-show="vms.form2.$validationSummary.length &gt; 0">
47+
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
48+
<h4><strong>ERRORS!</strong></h4>
49+
<ul>
50+
<li ng-repeat="item in vms.form2.$validationSummary">{{ item.field }}: {{item.message}}</li>
51+
</ul>
52+
</div>
53+
54+
<form name="vms.form2">
55+
<div class="form-group">
56+
<label for="input2">Validate IPV4 or IPV6 (required + IPV4 or IPV6 --&gt; validRequireHowMany="2")</label>
57+
<input type="text" class="form-control"
58+
name="input2"
59+
ng-model="vms.model.input2"
60+
placeholder="validation='ipv4|ipv6|required' ... validRequireHowMany='2'"
61+
valid-require-how-many="2" />
62+
</div>
63+
<br/>
64+
<div class="form-actions">
65+
<button type="submit" name="btn_ngDisabled2" class="btn btn-primary" ng-disabled="vms.form2.$invalid" >{{ 'SAVE' | translate }} (ngDisabled)</button>
66+
<button type="submit" name="btn_ngSubmit2" class="btn btn-primary" ng-click="vms.submitForm()">{{ 'SAVE' | translate }} (ngSubmit)</button>
67+
</div>
68+
</form>
69+
</div>
70+
</div>
71+
72+
<!-- external librairies CDN -->
73+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
74+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-route.js"></script>
75+
76+
<!-- angular-translate -->
77+
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
78+
<script src="../../vendors/angular-translate/angular-translate.min.js"></script>
79+
<script src="../../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
80+
81+
<!-- Angular-UI -->
82+
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.2.js"></script>
83+
84+
<!-- Angular-Validation -->
85+
<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>
86+
<!--
87+
<script type="text/javascript" src="../../src/validation-directive.js"></script>
88+
<script type="text/javascript" src="../../src/validation-service.js"></script>
89+
<script type="text/javascript" src="../../src/validation-common.js"></script>
90+
<script type="text/javascript" src="../../src/validation-rules.js"></script>
91+
-->
92+
93+
<!-- my application -->
94+
<script type="text/javascript" src="app.js"></script>
95+
</body>
96+
</html>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.4.17",
3+
"version": "1.4.18",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

protractor/conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'interpolate_spec.js',
3333
'ngIfDestroy_spec.js',
3434
'thirdParty_spec.js',
35+
'validRequireHowMany_spec.js',
3536
'full_tests_spec.js'
3637
],
3738
jasmineNodeOpts: {

0 commit comments

Comments
 (0)