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

Commit 6247356

Browse files
committed
Merge branch 'ghiscoding/master'
2 parents 916326c + 2266fc1 commit 6247356

12 files changed

+391
-210
lines changed

app.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ myApp.controller('CtrlValidationDirective', ['$scope', 'validationService', func
5050
}
5151
}
5252
$scope.showValidationSummary = function () {
53-
$translate.then(function() {
54-
$scope.displayValidationSummary = true;
55-
});
53+
$scope.displayValidationSummary = true;
5654
}
5755
}]);
5856

@@ -89,7 +87,7 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
8987
.addValidator('input10', 'date_iso|required')
9088
.addValidator('input11', 'date_us_long|required')
9189
.addValidator('input12', 'time')
92-
.addValidator('select1', 'required')
90+
.addValidator('select1', 'required:alt=' + $translate.instant('CHANGE_LANGUAGE'))
9391
.addValidator({elmName: 'input13', rules: 'min_len:5|max_len:10|alpha_dash_spaces|required', validationErrorTo: ".validation-input13"})
9492
.addValidator('input14', 'alpha|required')
9593
.addValidator('input15', 'alpha|min_len:3|required')
@@ -99,16 +97,14 @@ myApp.controller('CtrlValidationService', ['$scope', '$translate', 'validationSe
9997
.addValidator('input19', 'date_us_short_between:11/28/99,12/31/15|required')
10098
.addValidator('area1', 'alpha_dash_spaces|min_len:15|required');
10199

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

108106
$scope.showValidationSummary = function () {
109-
$translate.then(function() {
110-
$scope.displayValidationSummary = true;
111-
});
107+
$scope.displayValidationSummary = true;
112108
}
113109

114110
$scope.submitForm = 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.13",
44
"authors": [
55
"Ghislain B."
66
],

changelog.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ 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.
17+
1.3.13 (2015-04-07) Fixed $translate delay issue when using external JSON files

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

readme.md

Lines changed: 76 additions & 36 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.13`
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,21 @@ 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+
* [Alternate Text on Validator](#alternate)
26+
* [Available Validators](#validators)
27+
* [Bootstrap Input Groups Wrapping - HOWTO](#input-groups-wrapping)
28+
* [Changelog](#changelog)
29+
* [Demo - Plunker](#plunker)
30+
* [Dependencies](#dependencies)
31+
* [Form Submit and Validation](#submit)
2732
* [Install (bower)](#install)
2833
* [Include it in your app project](#project)
34+
* [Locales (languages)](#locales)
35+
* [Regular Expressions (Regex)](#regex)
2936
* [Requirements](#requirements)
3037
* [Some Working Examples (Directive)](#examples-directive)
3138
* [Some Working Examples (Service)](#examples-service)
32-
* [Form Submit and Validation](#submit)
3339
* [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)
3940

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

178179
// you can also remove a Validator with an ngClick or whichever way you prefer by calling .removeValidator()
179180
$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);
181+
// 1st argument is the object holding our $validationSummary `$scope.yourFormName`
182+
// If your form does not have a name attribute, your only choice is to use `$scope` as argument
183+
// 2nd argument, remove a single element (string)
184+
// OR you can also remove multiple elements through an array type .removeValidator($scope.form1, ['input2','input3'])
185+
myValidation.removeValidator($scope.form1, elmName);
182186
};
183187

184188
```
@@ -198,7 +202,7 @@ The Angular-Validation concept was first introduced with the use `ngDisabled` on
198202
```javascript
199203
// Option #2 will need to call the `checkFormValidity()` function checking the form before doing a real submit
200204
// $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)`
205+
// you can use `checkFormValidity($scope.yourFormName)` or this `checkFormValidity($scope)`
202206
// If your form does not have a name attribute, your only choice is `checkFormValidity($scope)`
203207
$scope.submitForm = function() {
204208
var myValidation = new validationService();
@@ -274,6 +278,26 @@ Well let's face it, having the `<span>` for error display right after the elemen
274278
<span class="validation-input1 validation text-danger"></span>
275279
```
276280

281+
<a name="locales"></a>
282+
Locales (languages)
283+
--------------------
284+
Locales are simple sets of language defined in external JSON files, we can easily add any new language as extra files without affecting the behaviour of the angular directive. You could even change displayed language on the fly (note that the error message will be reflected only after field value is re-evaluated). Make sure to include the `angular-translate` library and configure it, see section [Include it in your Project](#project)
285+
286+
NOTE: To be fully localized, I should add the country code at the end of my JSON filename and then change the suffix on the `angular-translate` `loader` method, but this would add an overhead and I prefer to keep it simple as validation messages often looks the same anyway (for example English from UK or US would most probably give similar error messages). If you really do want to be fully localized, then see the example in [Include it in your Project](#project)
287+
288+
```javascript
289+
// define a key, could be on the fly with a button or a menu link
290+
var key = 'fr';
291+
292+
// change the translation language & reload the page to make sure all errors were rendered properly
293+
$scope.switchLanguage = function (key) {
294+
$translate.use(key).then(function() {
295+
$route.reload();
296+
});
297+
};
298+
```
299+
*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.*
300+
277301
<a name="regex"></a>
278302
Regular Expressions (Regex)
279303
--------------------
@@ -294,44 +318,58 @@ Step #1-4 are for explanation only, at the end we show the full regex (make sure
294318

295319
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`
296320

297-
<a name="locales"></a>
298-
Locales (languages)
321+
<a name="alternate"></a>
322+
Alternate Text on Validators
299323
--------------------
300-
Locales are simple sets of language defined in external JSON files, we can easily add any new language as extra files without affecting the behaviour of the angular directive. You could even change displayed language on the fly (note that the error message will be reflected only after field value is re-evaluated). Make sure to include the `angular-translate` library and configure it, see section [Include it in your Project](#project)
324+
Validators can now use alternate text instead of the usual defined locale $translate text, for example seeing "Field is Required" on a `<select>` might not always be useful, it might be more useful to see an alternate text that is "Please choose an option". Alternate text works on all type of validators and is defined by adding `:alt=` at the end of any validators, it could be used on 1 or more validators directly inside the `validation=""` attribute. See the examples below.
325+
```html
326+
<!-- You can use translate in your HTML -->
327+
<!-- Example #1 with 1 alternate text on 1 of the 2 validators -->
328+
<input name="input1" validation="alpha|required:alt=Your Alternate Required Text." />
301329

302-
NOTE: To be fully localized, I should add the country code at the end of my JSON filename and then change the suffix on the `angular-translate` `loader` method, but this would add an overhead and I prefer to keep it simple as validation messages often looks the same anyway (for example English from UK or US would most probably give similar error messages). If you really do want to be fully localized, then see the example in [Include it in your Project](#project)
330+
<!-- Example #2, alternate text on multiple validators -->
331+
<input name="input1" validation="date_iso_between:2015-03-01,2015-03-30:alt=Booking date must be in April|required:alt=Booking Date is Required" />
332+
333+
<!-- Example #3, use $translate as alternate text -->
334+
<input name="input1" validation="min_len:5|required:alt={{ 'YOUR_TEXT' | translate }}" />
335+
```
303336

304337
```javascript
305-
// define a key, could be on the fly with a button or a menu link
306-
var key = 'fr';
338+
// When using the Validation Service
307339

308-
// change the translation language & reload the page to make sure all errors were rendered properly
309-
$scope.switchLanguage = function (key) {
310-
$translate.use(key).then(function() {
311-
$route.reload();
312-
});
313-
};
340+
myApp.controller('CtrlValidationService', function ($scope, $translate, validationService) {
341+
// Example #1 with 1 alternate text on 1 of the 2 validators
342+
myValidationService.addValidator('input1', 'alpha|required:alt=Your Alternate Required Text.');
343+
344+
// Example #2, alternate text on multiple validators
345+
myValidationService.addValidator('input1', 'date_iso_between:2015-03-01,2015-03-30:alt=Booking date must be in April|required:alt=Booking Date is Required');
346+
347+
// Example #3, use $translate as alternate text
348+
// you can use the $translate.instant() function
349+
myValidationService.addValidator('input1', 'min_len:5|required:alt=' + $translate.instant('YOUR_TEXT'))
350+
});
314351
```
315-
*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.*
316352

317353
<a name="validators"></a>
318354
Available Validators
319355
--------------------
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.
356+
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.
357+
321358
##### 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"`.
359+
322360
* `alpha` Only alpha characters (including latin) are present (a-z, A-Z)
323361
* `alpha_spaces` Only alpha characters (including latin) and spaces are present (a-z, A-Z)
324362
* `alpha_num` Only alpha-numeric characters (including latin) are present (a-z, A-Z, 0-9)
325363
* `alpha_num_spaces` Only alpha-numeric characters (with latin & spaces) are present (a-z, A-Z, 0-9)
326364
* `alpha_dash` Only alpha-numeric characters + dashes, underscores are present (a-z, A-Z, 0-9, _-)
327365
* `alpha_dash_spaces` Alpha-numeric chars + dashes, underscores and spaces (a-z, A-Z, 0-9, _-)
328-
* `between_len:min,max` Ensures the length of a string is between a min,max length.
329-
* `between_num:min,max` Ensures the numeric value is between a min,max number.
330366
* `between_date_iso:d1,d2` alias of `between_date_iso`.
331367
* `between_date_euro_long:d1,d2` alias of `date_euro_long_between`.
332368
* `between_date_euro_short:d1,d2` alias of `date_euro_short_between`.
333369
* `between_date_us_long:d1,d2` alias of `date_us_long_between`.
334370
* `between_date_us_short:d1,d2` alias of `date_us_short_between`.
371+
* `between_len:min,max` Ensures the length of a string is between a min,max length.
372+
* `between_num:min,max` Ensures the numeric value is between a min,max number.
335373
* `credit_card` Valid credit card number (AMEX, VISA, Mastercard, Diner's Club, Discover, JCB)
336374
* `date_iso` Ensure date follows the ISO format (yyyy-mm-dd)
337375
* `date_iso_between:d1,d2` Ensure date follows the ISO format and is between (d1) &amp; (d2)
@@ -366,27 +404,27 @@ All validators are written as `snake_case` but it's up to the user's taste and c
366404
* `ipv6` Check for valid IP (IPv6)
367405
* `ipv6_hex` Check for valid IP (IPv6 Hexadecimal)
368406
* `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.
407+
* `match:n,t` Match another input field(n), same as (match:n) but also include (t) for alternate input name to be displayed in the error message (it still uses default translated text, if you really wish to replace the complete text error, then use [:alt](#alternate))
370408
* `max_date_iso` alias of `date_iso_max`.
371-
* `min_date_iso` alias of `date_iso_min`.
372409
* `max_date_euro_long` alias of `date_euro_long_max`.
373-
* `min_date_euro_long` alias of `date_euro_long_min`.
374410
* `max_date_euro_short` alias of `date_euro_short_max`.
375-
* `min_date_euro_short` alias of `date_euro_short_min`.
376411
* `max_date_us_long` alias of `date_us_long_max`.
377-
* `min_date_us_long` alias of `date_us_long_min`.
378412
* `max_date_us_short` alias of `date_us_short_max`.
379-
* `min_date_us_short` alias of `date_us_short_min`.
380413
* `max_len:n` Checks field length, no longer than specified length where (n) is length parameter.
381414
* `max_num:n` Checks numeric value to be lower or equal than the number (n).
415+
* `min_date_iso` alias of `date_iso_min`.
416+
* `min_date_euro_long` alias of `date_euro_long_min`.
417+
* `min_date_euro_short` alias of `date_euro_short_min`.
418+
* `min_date_us_long` alias of `date_us_long_min`.
419+
* `min_date_us_short` alias of `date_us_short_min`.
382420
* `min_len:n` Checks field length, no shorter than specified length where (n) is length parameter.
383421
* `min_num:n` Checks numeric value to be higher or equal than the number (n).
384422
* `numeric` Only positive numeric value (float, integer).
385423
* `numeric_signed` Only numeric value (float, integer) can also be signed (-/+).
386424
* `regex` Ensure it follows a regular expression pattern... please see [Regex](#regex) section
387425
* `required` Ensures the specified key value exists and is not empty
388-
* `url` Check for valid URL or subdomain
389426
* `time` Ensure time follows the format of (hh:mm) or (hh:mm:ss)
427+
* `url` Check for valid URL or subdomain
390428

391429
<a name="dependencies"></a>
392430
Dependencies
@@ -418,4 +456,6 @@ License
418456
* [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)
419457
* [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.
420458
* [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.
459+
* [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.
460+
* [1.3.12](https://github.com/ghiscoding/angular-validation/commit/0af82337a6961923e3b022a19660237d3e6f7184) `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.
461+
* [1.3.13](https://github.com/ghiscoding/angular-validation/commit/d0440bdd7fc2816e03d28ad3a9c3bd7bee8ac519) `2015-04-07` Fixed $translate delay issue when using external JSON files

0 commit comments

Comments
 (0)