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

Commit

Permalink
Added enhancement #35 - PreValidate the Form
Browse files Browse the repository at this point in the history
- Added enhancement #35 - PreValidate the Form, display all errors on
page load.
  • Loading branch information
ghiscoding committed May 30, 2015
1 parent 9edaa13 commit 00514f6
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 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.3.25",
"version": "1.3.26",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Angular-Validation change logs
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).
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.
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.
1.3.25 (2015-05-19) Enhancement #34 to add Remote Validation and updated Protractor to cover this new feature.
1.3.25 (2015-05-19) Enhancement #34 to add Remote Validation and updated Protractor to cover this new feature.
1.3.26 (2015-05-30) Added enhancement #35 - PreValidate the Form, display all errors on page load.
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion full-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
<script src="../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>

<!-- Angular-Validation -->
<!--<script type="text/javascript" src="../dist/angular-validation.min.js"></script>-->
<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>
-->

<!-- your ng-app file -->
<script type="text/javascript" src="app.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"INVALID_PATTERN": "Doit suivre le format: {0}. ",
"INVALID_REQUIRED": "Le champ est requis. ",
"INVALID_URL": "Doit être un URL valide. ",
"INVALID_TIME": "Doit être un format de date valide (hh:mm) OU (hh:mm:ss). ",
"INVALID_TIME": "Doit être un format de temps valide (hh:mm) OU (hh:mm:ss). ",
"INVALID_CHECKBOX_SELECTED": "La case à cocher doit être sélectionnée. ",

"AREA1": "TextArea: Alphanumérique + Minimum(15) + Required",
Expand Down
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.3.25",
"version": "1.3.26",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.3.25`
`Version: 1.3.26`
### Form validation after user inactivity of default 1sec. (customizable timeout)

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!
Expand Down Expand Up @@ -73,6 +73,7 @@ All the documentation has been moved to the Wiki section, see the [github wiki](
* [Service Examples](https://github.com/ghiscoding/angular-validation/wiki/Working-Service-Examples)
* [Alternate Text on Validators](https://github.com/ghiscoding/angular-validation/wiki/Alternate-Text-on-Validators)
* [DisplayErrorTo](https://github.com/ghiscoding/angular-validation/wiki/Bootstrap-Input-Groups-Wrapping)
* [PreValidate Form (on page load)](https://github.com/ghiscoding/angular-validation/wiki/PreValidate-Form-(on-page-load))
* [Remote Validation (AJAX)](https://github.com/ghiscoding/angular-validation/wiki/Remote-Validation-(AJAX))
* [Remove a Validator](https://github.com/ghiscoding/angular-validation/wiki/Remove-Validator-from-Element)
* [Submit and Validation](https://github.com/ghiscoding/angular-validation/wiki/Form-Submit-and-Validation)
Expand Down
18 changes: 16 additions & 2 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ angular

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

// user might have passed a message to be translated
Expand Down Expand Up @@ -520,8 +521,17 @@ angular
formElmObj.message = message;
}

// if user is pre-validating all form elements, display error right away
if(self.validatorAttrs.preValidateFormElements || (!!self.scope.$validationOptions && self.scope.$validationOptions.hasOwnProperty('preValidateFormElements'))) {
// make the element as it was touched for CSS, only works in AngularJS 1.3+
if (!!formElmObj && typeof self.ctrl.$setTouched === "function") {
formElmObj.ctrl.$setTouched();
}
updateErrorMsg(message, { isSubmitted: true, isValid: isFieldValid, obj: formElmObj });
}

// error Display
if(showError && !formElmObj.isValid) {
if(showError && !!formElmObj && !formElmObj.isValid) {
self.updateErrorMsg(message, { isValid: isFieldValid });
}else if(!!formElmObj && formElmObj.isValid) {
addToValidationSummary(formElmObj, '');
Expand All @@ -533,6 +543,10 @@ angular
* @param string message: error message
*/
function addToValidationSummary(self, message) {
if(typeof self === "undefined" || self == null) {
return;
}

// get the element name, whichever we find it
var elmName = (!!self.validatorAttrs && !!self.validatorAttrs.name)
? self.validatorAttrs.name
Expand Down

0 comments on commit 00514f6

Please sign in to comment.