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

Commit 00514f6

Browse files
committed
Added enhancement #35 - PreValidate the Form
- Added enhancement #35 - PreValidate the Form, display all errors on page load.
1 parent 9edaa13 commit 00514f6

File tree

8 files changed

+29
-11
lines changed

8 files changed

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

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ Angular-Validation change logs
2626
1.3.22 (2015-05-03) Added new element attribute of `friendly-name` which is used ONLY in the ValidationSummary, this friendly name is to give a better element name display, which also support translation, inside the ValidationSummary instead of just "input1" (see ValidationSummary for more details).
2727
1.3.23 (2015-05-05) Added option to display only last error message instead of all messages at once. Fixed a bug where changing route on View/Controller would make the ValidationSummary fail when coming back to original View/Controller, this bug was associated to the fact that the ValidationSummary kept growing from Controller to Controller, now this ValidationSummary is wipe out as soon as we detect a route change.
2828
1.3.24 (2015-05-17) Replaced all `:param` inside each locale translations with a better standard of {0}, {1}, etc.. like C# `String.Format()`. Added a full Protractor End-to-End test suite (1000+ asserts). Fixed a few minor bugs found with Protractor test cases. Fixed issue #36, bower.json scripts in wrong order.
29-
1.3.25 (2015-05-19) Enhancement #34 to add Remote Validation and updated Protractor to cover this new feature.
29+
1.3.25 (2015-05-19) Enhancement #34 to add Remote Validation and updated Protractor to cover this new feature.
30+
1.3.26 (2015-05-30) Added enhancement #35 - PreValidate the Form, display all errors on page load.

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.

full-tests/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
4444
<script src="../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
4545

4646
<!-- Angular-Validation -->
47-
<!--<script type="text/javascript" src="../dist/angular-validation.min.js"></script>-->
47+
<script type="text/javascript" src="../dist/angular-validation.min.js"></script>
48+
<!--
4849
<script type="text/javascript" src="../src/validation-directive.js"></script>
4950
<script type="text/javascript" src="../src/validation-service.js"></script>
5051
<script type="text/javascript" src="../src/validation-common.js"></script>
5152
<script type="text/javascript" src="../src/validation-rules.js"></script>
53+
-->
5254

5355
<!-- your ng-app file -->
5456
<script type="text/javascript" src="app.js"></script>

locales/validation/fr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"INVALID_PATTERN": "Doit suivre le format: {0}. ",
5151
"INVALID_REQUIRED": "Le champ est requis. ",
5252
"INVALID_URL": "Doit être un URL valide. ",
53-
"INVALID_TIME": "Doit être un format de date valide (hh:mm) OU (hh:mm:ss). ",
53+
"INVALID_TIME": "Doit être un format de temps valide (hh:mm) OU (hh:mm:ss). ",
5454
"INVALID_CHECKBOX_SELECTED": "La case à cocher doit être sélectionnée. ",
5555

5656
"AREA1": "TextArea: Alphanumérique + Minimum(15) + Required",

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

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.3.25`
2+
`Version: 1.3.26`
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!
@@ -73,6 +73,7 @@ All the documentation has been moved to the Wiki section, see the [github wiki](
7373
* [Service Examples](https://github.com/ghiscoding/angular-validation/wiki/Working-Service-Examples)
7474
* [Alternate Text on Validators](https://github.com/ghiscoding/angular-validation/wiki/Alternate-Text-on-Validators)
7575
* [DisplayErrorTo](https://github.com/ghiscoding/angular-validation/wiki/Bootstrap-Input-Groups-Wrapping)
76+
* [PreValidate Form (on page load)](https://github.com/ghiscoding/angular-validation/wiki/PreValidate-Form-(on-page-load))
7677
* [Remote Validation (AJAX)](https://github.com/ghiscoding/angular-validation/wiki/Remote-Validation-(AJAX))
7778
* [Remove a Validator](https://github.com/ghiscoding/angular-validation/wiki/Remove-Validator-from-Element)
7879
* [Submit and Validation](https://github.com/ghiscoding/angular-validation/wiki/Form-Submit-and-Validation)

src/validation-common.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ angular
242242

243243
// Make sure that element has a name="" attribute else it will not work
244244
if(typeof elmName === "undefined" || elmName === null) {
245-
throw 'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="' + elm.attr('ng-model') + '"';
245+
var ngModelName = (!!elm) ? elm.attr('ng-model') : 'unknown';
246+
throw 'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="' + ngModelName + '"';
246247
}
247248

248249
// user might have passed a message to be translated
@@ -520,8 +521,17 @@ angular
520521
formElmObj.message = message;
521522
}
522523

524+
// if user is pre-validating all form elements, display error right away
525+
if(self.validatorAttrs.preValidateFormElements || (!!self.scope.$validationOptions && self.scope.$validationOptions.hasOwnProperty('preValidateFormElements'))) {
526+
// make the element as it was touched for CSS, only works in AngularJS 1.3+
527+
if (!!formElmObj && typeof self.ctrl.$setTouched === "function") {
528+
formElmObj.ctrl.$setTouched();
529+
}
530+
updateErrorMsg(message, { isSubmitted: true, isValid: isFieldValid, obj: formElmObj });
531+
}
532+
523533
// error Display
524-
if(showError && !formElmObj.isValid) {
534+
if(showError && !!formElmObj && !formElmObj.isValid) {
525535
self.updateErrorMsg(message, { isValid: isFieldValid });
526536
}else if(!!formElmObj && formElmObj.isValid) {
527537
addToValidationSummary(formElmObj, '');
@@ -533,6 +543,10 @@ angular
533543
* @param string message: error message
534544
*/
535545
function addToValidationSummary(self, message) {
546+
if(typeof self === "undefined" || self == null) {
547+
return;
548+
}
549+
536550
// get the element name, whichever we find it
537551
var elmName = (!!self.validatorAttrs && !!self.validatorAttrs.name)
538552
? self.validatorAttrs.name

0 commit comments

Comments
 (0)