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

Commit

Permalink
Fixed issue #121 alternate text containing char ":"
Browse files Browse the repository at this point in the history
The char ":" is used for splitting arguments in validation, but it
shouldn't be split when it is part of an alternate text.
  • Loading branch information
ghiscoding committed Jun 15, 2016
1 parent 30e5f75 commit 2f8570b
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.1",
"version": "1.5.2",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions more-examples/ngModelOptionBlur/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var myApp = angular.module('myApp', ['ghiscoding.validation', 'pascalprecht.translate']);
// --
// configuration
myApp.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}])
.config(['$translateProvider', function ($translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: '../../locales/validation/',
suffix: '.json'
});
// load English ('en') table on startup
$translateProvider.preferredLanguage('en').fallbackLanguage('en');
$translateProvider.useSanitizeValueStrategy('escapeParameters');
}]);

// --
// Directive
myApp.controller('CtrlDirective', ['ValidationService', function (ValidationService) {
var vmd = this;
vmd.model = {};

// use the ValidationService only to declare the controllerAs syntax
var vs = new ValidationService({ controllerAs: vmd });

vmd.input6 = "initialInput6";
vmd.mylocation = { Name: "initialName", Name2: "initialName", Simple: "initialName" };

vmd.submitForm = function() {
if(vs.checkFormValidity(vmd.form1)) {
alert('All good, proceed with submit...');
}
}
}]);
85 changes: 85 additions & 0 deletions more-examples/ngModelOptionBlur/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html ng-app="myApp" ng-strict-di ng-cloak="">
<head>
<meta charset="utf-8" />
<title>Angular-Validation with Custom Javascript function</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="../../style.css">
</head>

<body>
<div class="container">
<h2>Example of Angular-Validation with Custom Javascript function</h2>

<div ng-controller="CtrlDirective as Location">
<div class="row">
<div>
<form class="form-horizontal" name="locationForm" novalidate ng-model-options="{ updateOn: 'blur' }">

<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="labels" for="name">Name *</label>
<input type="text"
name="name"
id="name"
validation="required|max_len:50"
debounce="0"
ng-model="Location.mylocation.Name"
class="form-control input-lg input-full"
placeholder="Enter Location Name">
</section>
<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="labels" for="name">Simple Input *</label>
<input type="text"
name="simple"
id="simple"
validation="required|max_len:50"
debounce="0"
ng-model="Location.mylocation.Simple" />
</section>
</form>
<h3>Control below NOT in a form, doesn't have problem</h3>
<!--// NOT in form-->
<section class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class="labels" for="name2">Name2 *</label>
<input type="text"
name="name2"
id="name2"
validation="required:alt=Please Enter Name|max_len:50"
debounce="0"
ng-model="Location.mylocation.Name2"
class="form-control input-lg input-full"
placeholder="Enter Location Name">
</section>

</div>
</div>
</div>
</div>

<!-- external librairies CDN -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-sanitize.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>

<!-- angular-translate -->
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
<script src="../../vendors/angular-translate/angular-translate.min.js"></script>
<script src="../../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>

<!-- IBAN external library -->
<script src="../../vendors/iban/iban.js"></script>

<!-- Angular-Validation -->
<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>
<!--
<script type="text/javascript" src="../../src/validation-directive.js"></script>
<script type="text/javascript" src="../../src/validation-service.js"></script>
<script type="text/javascript" src="../../src/validation-common.js"></script>
<script type="text/javascript" src="../../src/validation-rules.js"></script>
-->

<!-- my application -->
<script type="text/javascript" src="app.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.5.1",
"version": "1.5.2",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.5.1`
`Version: 1.5.2`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

Expand Down
17 changes: 13 additions & 4 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,20 @@ angular

// loop through all validators of the element
for (var i = 0, ln = validations.length; i < ln; i++) {
// params split will be:: [0]=rule, [1]=ruleExtraParams OR altText, [2] altText
var params = validations[i].split(':');

// check if user provided an alternate text to his validator (validator:alt=Alternate Text)
var hasAltText = validations[i].indexOf("alt=") >= 0;
var posAltText = validations[i].indexOf("alt=");
var hasAltText = posAltText >= 0;
var params = [];

// alternate text might have the character ":" inside it, so we need to compensate
// since altText is always at the end, we can before the altText and add back this untouched altText to our params array
if(hasAltText) {
params = validations[i].substring(0,posAltText-1).split(':'); // split before altText, so we won't touch it
params.push(validations[i].substring(posAltText)); // add back the altText to our split params array
}else {
// params split will be:: [0]=rule, [1]=ruleExtraParams OR altText, [2] altText
params = validations[i].split(':');
}

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

0 comments on commit 2f8570b

Please sign in to comment.