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

Commit 0af8233

Browse files
committed
Fixed #16 and added Validators Alternate Text
- Fixed issue #16 - Added Validators Alternate Text - Fixed Service .removeValidator( ) - Clean a lot of code
1 parent 17f7216 commit 0af8233

12 files changed

+349
-205
lines changed

app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
8989
.addValidator('input10', 'date_iso|required')
9090
.addValidator('input11', 'date_us_long|required')
9191
.addValidator('input12', 'time')
92-
.addValidator('select1', 'required')
92+
.addValidator('select1', 'required:alt=' + $translate.instant('CHANGE_LANGUAGE'))
9393
.addValidator({elmName: 'input13', rules: 'min_len:5|max_len:10|alpha_dash_spaces|required', validationErrorTo: ".validation-input13"})
9494
.addValidator('input14', 'alpha|required')
9595
.addValidator('input15', 'alpha|min_len:3|required')
@@ -99,10 +99,10 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
9999
.addValidator('input19', 'date_us_short_between:11/28/99,12/31/15|required')
100100
.addValidator('area1', 'alpha_dash_spaces|min_len:15|required');
101101

102-
// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
102+
// remove a single element ($scope.form1, string)
103+
// OR you can also remove multiple elements through an array type .removeValidator($scope.form1, ['input2','input3'])
103104
$scope.removeInputValidator = function ( elmName ) {
104-
myValidation.removeValidator(elmName);
105-
$scope.enableRemoveInputValidatorButton = false;
105+
myValidation.removeValidator($scope.form1, elmName);
106106
};
107107

108108
$scope.showValidationSummary = function () {

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.11",
3+
"version": "1.3.12",
44
"authors": [
55
"Ghislain B."
66
],

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ Angular-Validation change logs
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)
1313
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.
1414
1.3.10 (2015-03-28): Added new function of `checkFormValidity()` before submitting the form. Now use only 1 minified script instead of multiples.
15-
1.3.11 (2015-03-30): Accepted pull request #15 to fix form without name attribute. Also accepted pull request #18 to add Spanish locales.
15+
1.3.11 (2015-03-30): Accepted pull request #15 to fix form without name attribute. Also accepted pull request #18 to add Spanish locales.
16+
1.3.12 (2015-04-04): Fix issue #16 and added Validators Alternate Text option on all type of validators. Also fixed removeValidator and clean a lot of code.

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.

package.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.11",
3+
"version": "1.3.12",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

readme.md

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.3.11`
2+
`Version: 1.3.12`
33
### Form validation after user inactivity of default 1sec. (customizable timeout)
44

55
Forms Validation with Angular made easy! Angular-Validation is an angular directive/service with locales (languages) with a very simple approach of defining your `validation=""` directly within your element to validate (input, textarea, etc) and...that's it!!! The directive/service will take care of the rest!
@@ -22,20 +22,20 @@ Huge rewrite to have a better code separation and also adding support to Service
2222

2323
<a name="index"></a>
2424
## Index
25-
* [Plunker Demo](#plunker)
26-
* [Dependency](#dependencies)
25+
* [Available Validators](#validators)
26+
* [Bootstrap Input Groups Wrapping - HOWTO](#input-groups-wrapping)
27+
* [Changelog](#changelog)
28+
* [Demo - Plunker](#plunker)
29+
* [Dependencies](#dependencies)
30+
* [Form Submit and Validation](#submit)
2731
* [Install (bower)](#install)
2832
* [Include it in your app project](#project)
33+
* [Locales (languages)](#locales)
34+
* [Regular Expressions (Regex)](#regex)
2935
* [Requirements](#requirements)
3036
* [Some Working Examples (Directive)](#examples-directive)
3137
* [Some Working Examples (Service)](#examples-service)
32-
* [Form Submit and Validation](#submit)
3338
* [Validation summary](#validation-summary)
34-
* [Bootstrap Input Groups Wrapping - HOWTO](#input-groups-wrapping)
35-
* [Regular Expressions (Regex)](#regex)
36-
* [Locales (languages)](#locales)
37-
* [Available Validators](#validators)
38-
* [Changelog](#changelog)
3939

4040
<a name="install"></a>
4141
Install
@@ -177,8 +177,11 @@ P.S. For real live sample, see the [live demo](#plunker) or download the Github
177177

178178
// you can also remove a Validator with an ngClick or whichever way you prefer by calling .removeValidator()
179179
$scope.removeInputValidator = function ( elmName ) {
180-
// remove a single element (string) OR you can also remove multiple elements through an array type .removeValidator(['input2','input3'])
181-
myValidation.removeValidator(elmName);
180+
// 1st argument is the object holding our $validationSummary `$scope.yourFormName`
181+
// If your form does not have a name attribute, your only choice is to use `$scope` as argument
182+
// 2nd argument, remove a single element (string)
183+
// OR you can also remove multiple elements through an array type .removeValidator($scope.form1, ['input2','input3'])
184+
myValidation.removeValidator($scope.form1, elmName);
182185
};
183186

184187
```
@@ -198,7 +201,7 @@ The Angular-Validation concept was first introduced with the use `ngDisabled` on
198201
```javascript
199202
// Option #2 will need to call the `checkFormValidity()` function checking the form before doing a real submit
200203
// $validationSummary can be found in 2 variables (depending if your form as a name or not)
201-
// you can use `checkFormValidity($scope.form1)` or this `checkFormValidity($scope)`
204+
// you can use `checkFormValidity($scope.yourFormName)` or this `checkFormValidity($scope)`
202205
// If your form does not have a name attribute, your only choice is `checkFormValidity($scope)`
203206
$scope.submitForm = function() {
204207
var myValidation = new validationService();
@@ -274,26 +277,6 @@ Well let's face it, having the `<span>` for error display right after the elemen
274277
<span class="validation-input1 validation text-danger"></span>
275278
```
276279

277-
<a name="regex"></a>
278-
Regular Expressions (Regex)
279-
--------------------
280-
From the example displayed, I introduce the custom regular expression, there is no limitation on regex itself and you can even use the pipe " | " within it and without being scared of interfering with the other validation filters BUT you have to follow a specific pattern (a writing pattern that is), and if you don't, well it will simply fail. Let's explain how it works...
281-
282-
Regex validation is divided in 4 specific parts (Step #1-4).
283-
284-
Let's use the previous [Examples #5](#examples-directive) and extract the information out of it to see how it works.
285-
Step #1-4 are for explanation only, at the end we show the full regex (make sure there is no spaces).
286-
287-
1. Start &amp; end the filter with the following `regex: :regex` which tells the directive where to extract it.
288-
289-
2. Custom error message `YYWW` (what do we want to display to the user, it will be appended to INVALID_PATTERN, refer to the translation file. In english it will display the following: Must be following this format: YYWW)
290-
291-
3. Followed by a separator which basically says... after `:=` separator comes the regex pattern
292-
293-
4. Custom regex pattern `^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$`
294-
295-
Final code (without spaces): `regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex`
296-
297280
<a name="locales"></a>
298281
Locales (languages)
299282
--------------------
@@ -314,11 +297,35 @@ $scope.switchLanguage = function (key) {
314297
```
315298
*P.S. If you define a new Language set, please make a pull request and I would be happy to add them in current project... It would be nice to have Spanish, German or even Chinese :) Thank you.*
316299

300+
<a name="regex"></a>
301+
Regular Expressions (Regex)
302+
--------------------
303+
From the example displayed, I introduce the custom regular expression, there is no limitation on regex itself and you can even use the pipe " | " within it and without being scared of interfering with the other validation filters BUT you have to follow a specific pattern (a writing pattern that is), and if you don't, well it will simply fail. Let's explain how it works...
304+
305+
Regex validation is divided in 4 specific parts (Step #1-4).
306+
307+
Let's use the previous [Examples #5](#examples-directive) and extract the information out of it to see how it works.
308+
Step #1-4 are for explanation only, at the end we show the full regex (make sure there is no spaces).
309+
310+
1. Start &amp; end the filter with the following `regex: :regex` which tells the directive where to extract it.
311+
312+
2. Custom error message `YYWW` (what do we want to display to the user, it will be appended to INVALID_PATTERN, refer to the translation file. In english it will display the following: Must be following this format: YYWW)
313+
314+
3. Followed by a separator which basically says... after `:=` separator comes the regex pattern
315+
316+
4. Custom regex pattern `^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$`
317+
318+
Final code (without spaces): `regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex`
319+
317320
<a name="validators"></a>
318321
Available Validators
319322
--------------------
320-
All validators are written as `snake_case` but it's up to the user's taste and could also be written as `camelCase`. So for example `alpha_dash_spaces` and `alphaDashSpaces` are both equivalent.
323+
All validators are written as `snake_case` but it's up to the user's taste and could also be used as `camelCase`. So for example `alpha_dash_spaces` and `alphaDashSpaces` are both equivalent.
324+
325+
NEW Alternate Text: Validators can now use alternate text instead of the usual defined locale $translate text, for example it could be useful to see a different text on a `<select>` instead of the usual "Field is Required". This works on all type of validators and is defined by adding `:alt=` at the end of any validator and could be used on 1 validator or multiple validators. For example: `validation="required:alt=Your Alternate Required Text."` or `validation="date_iso_between:2015-03-01,2015-03-30:alt=Provide a Booking Date for April|required:Booking Date is Required"`. You could also use the `$translate` on the provided text, for example in the Directive you can use `validation="required: {{ 'YOUR_TEXT' | translate }}"` or in the Service you can use `....addValidator('input1', 'required:alt=' + $translate.instant('YOUR_TEXT'));`
326+
321327
##### NOTE: on an `input type="number"`, the `+` sign is an invalid character (browser restriction) even if you are using a `signed` validator. If you really wish to use the `+`, then change your input to a `type="text"`.
328+
322329
* `alpha` Only alpha characters (including latin) are present (a-z, A-Z)
323330
* `alpha_spaces` Only alpha characters (including latin) and spaces are present (a-z, A-Z)
324331
* `alpha_num` Only alpha-numeric characters (including latin) are present (a-z, A-Z, 0-9)
@@ -366,7 +373,7 @@ All validators are written as `snake_case` but it's up to the user's taste and c
366373
* `ipv6` Check for valid IP (IPv6)
367374
* `ipv6_hex` Check for valid IP (IPv6 Hexadecimal)
368375
* `match:n` Match another input field(n), where (n) must be the exact ngModel attribute of input field to compare to.
369-
* `match:n,t` Match another input field(n), same as (match:n) but also include (t) for alternative text to be displayed in the error message.
376+
* `match:n,t` Match another input field(n), same as (match:n) but also include (t) for alternate text (this only replace the input name) to be displayed in the error message.
370377
* `max_date_iso` alias of `date_iso_max`.
371378
* `min_date_iso` alias of `date_iso_min`.
372379
* `max_date_euro_long` alias of `date_euro_long_max`.
@@ -418,4 +425,5 @@ License
418425
* [1.3.8](https://github.com/ghiscoding/angular-validation/commit/492d1060a91fb8b49fc70a0c7a1a581d904e0db0) `2015-03-15` Added between/min/max conditional validators on all Date types (iso, euro_long, euro_short, us_long, us_short)
419426
* [1.3.9](https://github.com/ghiscoding/angular-validation/commit/931d3b04a00f0583612aefe28ad0bfcac326a38c) `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.
420427
* [1.3.10](https://github.com/ghiscoding/angular-validation/commit/18765a8dd986856a9fa176fc4835d90d25f663b2) `2015-03-29` Added new function of `checkFormValidity()` before submitting the form. Now use only 1 minified script instead of multiples.
421-
* [1.3.11](https://github.com/ghiscoding/angular-validation/commit/e807584f0bcdf0f28ef2ef905b6bc4e890926ac1) `2015-03-30` Accepted pull request #15 to fix form without name attribute. Also accepted pull request #18 to add Spanish locales.
428+
* [1.3.11](https://github.com/ghiscoding/angular-validation/commit/e807584f0bcdf0f28ef2ef905b6bc4e890926ac1) `2015-03-30` Accepted pull request #15 to fix form without name attribute. Also accepted pull request #18 to add Spanish locales.
429+
* [1.3.12]() `2015-04-04` Fix issue #16 and added Validators Alternate Text option on all type of validators. Also fixed removeValidator and clean a lot of code.

0 commit comments

Comments
 (0)