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

Commit 2f8570b

Browse files
committed
Fixed issue #121 alternate text containing char ":"
The char ":" is used for splitting arguments in validation, but it shouldn't be split when it is part of an alternate text.
1 parent 30e5f75 commit 2f8570b

File tree

7 files changed

+140
-10
lines changed

7 files changed

+140
-10
lines changed

bower.json

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

dist/angular-validation.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
var myApp = angular.module('myApp', ['ghiscoding.validation', 'pascalprecht.translate']);
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.input6 = "initialInput6";
29+
vmd.mylocation = { Name: "initialName", Name2: "initialName", Simple: "initialName" };
30+
31+
vmd.submitForm = function() {
32+
if(vs.checkFormValidity(vmd.form1)) {
33+
alert('All good, proceed with submit...');
34+
}
35+
}
36+
}]);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 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>
11+
<div class="container">
12+
<h2>Example of Angular-Validation with Custom Javascript function</h2>
13+
14+
<div ng-controller="CtrlDirective as Location">
15+
<div class="row">
16+
<div>
17+
<form class="form-horizontal" name="locationForm" novalidate ng-model-options="{ updateOn: 'blur' }">
18+
19+
<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
20+
<label class="labels" for="name">Name *</label>
21+
<input type="text"
22+
name="name"
23+
id="name"
24+
validation="required|max_len:50"
25+
debounce="0"
26+
ng-model="Location.mylocation.Name"
27+
class="form-control input-lg input-full"
28+
placeholder="Enter Location Name">
29+
</section>
30+
<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
31+
<label class="labels" for="name">Simple Input *</label>
32+
<input type="text"
33+
name="simple"
34+
id="simple"
35+
validation="required|max_len:50"
36+
debounce="0"
37+
ng-model="Location.mylocation.Simple" />
38+
</section>
39+
</form>
40+
<h3>Control below NOT in a form, doesn't have problem</h3>
41+
<!--// NOT in form-->
42+
<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
43+
<label class="labels" for="name2">Name2 *</label>
44+
<input type="text"
45+
name="name2"
46+
id="name2"
47+
validation="required:alt=Please Enter Name|max_len:50"
48+
debounce="0"
49+
ng-model="Location.mylocation.Name2"
50+
class="form-control input-lg input-full"
51+
placeholder="Enter Location Name">
52+
</section>
53+
54+
</div>
55+
</div>
56+
</div>
57+
</div>
58+
59+
<!-- external librairies CDN -->
60+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
61+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
62+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-sanitize.js"></script>
63+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>
64+
65+
<!-- angular-translate -->
66+
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
67+
<script src="../../vendors/angular-translate/angular-translate.min.js"></script>
68+
<script src="../../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
69+
70+
<!-- IBAN external library -->
71+
<script src="../../vendors/iban/iban.js"></script>
72+
73+
<!-- Angular-Validation -->
74+
<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>
75+
<!--
76+
<script type="text/javascript" src="../../src/validation-directive.js"></script>
77+
<script type="text/javascript" src="../../src/validation-service.js"></script>
78+
<script type="text/javascript" src="../../src/validation-common.js"></script>
79+
<script type="text/javascript" src="../../src/validation-rules.js"></script>
80+
-->
81+
82+
<!-- my application -->
83+
<script type="text/javascript" src="app.js"></script>
84+
</body>
85+
</html>

package.json

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

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.5.1`
2+
`Version: 1.5.2`
33
### Forms Validation with Angular made easy!
44
##### (Concept comes from the amazing Laravel)
55

src/validation-common.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,20 @@ angular
235235

236236
// loop through all validators of the element
237237
for (var i = 0, ln = validations.length; i < ln; i++) {
238-
// params split will be:: [0]=rule, [1]=ruleExtraParams OR altText, [2] altText
239-
var params = validations[i].split(':');
240-
241238
// check if user provided an alternate text to his validator (validator:alt=Alternate Text)
242-
var hasAltText = validations[i].indexOf("alt=") >= 0;
239+
var posAltText = validations[i].indexOf("alt=");
240+
var hasAltText = posAltText >= 0;
241+
var params = [];
242+
243+
// alternate text might have the character ":" inside it, so we need to compensate
244+
// since altText is always at the end, we can before the altText and add back this untouched altText to our params array
245+
if(hasAltText) {
246+
params = validations[i].substring(0,posAltText-1).split(':'); // split before altText, so we won't touch it
247+
params.push(validations[i].substring(posAltText)); // add back the altText to our split params array
248+
}else {
249+
// params split will be:: [0]=rule, [1]=ruleExtraParams OR altText, [2] altText
250+
params = validations[i].split(':');
251+
}
243252

244253
self.validators[i] = ValidationRules.getElementValidators({
245254
altText: hasAltText === true ? (params.length === 2 ? params[1] : params[2]) : '',

0 commit comments

Comments
 (0)