` for displaying the possible error and give the this element an `id="someId"` or a `class="className"` and then reference it inside our input. We could actually move the error element anywhere we want with this method, just don't forget to name it with an `id` or a `className` and call the `validation-error-to` attribute. This attribute could be called in 3 different ways: with `'.'` (element error className) or with/without `'#'` (element error id) We could even do a validation summary with this...just saying hehe.
@@ -250,7 +281,7 @@ From the example displayed, I introduce the custom regular expression, there is
Regex validation is divided in 4 specific parts (Step #1-4).
-Let's use the previous [Examples #5](#examples-directives) and extract the information out of it to see how it works.
+Let's use the previous [Examples #5](#examples-directive) and extract the information out of it to see how it works.
Step #1-4 are for explanation only, at the end we show the full regex (make sure there is no spaces).
1. Start & end the filter with the following `regex: :regex` which tells the directive where to extract it.
@@ -263,12 +294,12 @@ Step #1-4 are for explanation only, at the end we show the full regex (make sure
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`
-
+
Locales (languages)
--------------------
-Locales are simply 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, well of course the error message will be reflected only after field value is re-evaluated. You of course have to include the `angular-translate` library and configure it, see section [Include it in your Project](#project)
+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)
-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 then this would add an overhead and I prefer to keep it simple as validation messages often looks the same anyway. If you do want to be fully localized, then see the example in [Include it in your Project](#project)
+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)
```javascript
// define a key, could be on the fly with a button or a menu link
@@ -281,9 +312,9 @@ $scope.switchLanguage = function (key) {
});
};
```
-
*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.*
+
Available Validators
--------------------
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.
@@ -374,6 +405,7 @@ License
* Add more validators...
* Add more locale languages... I need your help on that one!!!
+
## CHANGELOG
* [1.3.0](https://github.com/ghiscoding/angular-validation/commit/d106996926bef86a0457c90fbb65fe6233f3928d) `2014-12-01` Added support to AngularJS 1.3
* [1.3.1](https://github.com/ghiscoding/angular-validation/commit/44fe9de050504a46bb0eb975c31bc4b0f3b6f516) `2015-01-02` Added Input Match/Confirmation Validator, ex: password confirmation.
@@ -383,6 +415,7 @@ License
* [1.3.5](https://github.com/ghiscoding/angular-validation/commit/679b24ca4daee8419731c45d1d65d63cb5ca74a5) `2015-01-26` Throw an error message when user did not provide a `name=""` property inside the element to validate.
* [1.3.6](https://github.com/ghiscoding/angular-validation/commit/e47e91f45f93a3f191ab6849d06163563674e9e2) `2015-02-09` Added `ng-strict-di` for minification, renamed some files and folder lib to `/vendors`, moved directive into new `/src` folder for better separation.
* [1.3.7](https://github.com/ghiscoding/angular-validation/commit/86c16f720d6687d3b5ca93e49a0a37824027e583) `2015-03-08` Complete rewrite (but same functionality) so that I could add an Angular-Validation Service which is similar implementation as the Directive. Also added `debounce` attribute which is an alias to `typingLimit`, validation rules are now defined as an external service for better maintainability and also created a common file for shared functions by both Validation Directive and Service.
-* [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)
+* [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)
* [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.
-* [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.
\ No newline at end of file
+* [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.
+* [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.
\ No newline at end of file
diff --git a/src/validation-common.js b/src/validation-common.js
index 74422cb..8877b3d 100644
--- a/src/validation-common.js
+++ b/src/validation-common.js
@@ -283,21 +283,7 @@ angular
//----
// Private functions declaration
//----------------------------------
-
- /** Get form within scope (if found)
- * @param self
- */
- function getScopeForm(self) {
- var forms = document.querySelectorAll('form');
- for (var i = 0; i < forms.length; i++) {
- var form = document.querySelectorAll('form')[i];
- if (form && form.name && self.scope[form.name]) {
- return self.scope[form.name];
- }
- }
- return null;
- }
-
+
/** Add the error to the validation summary
* @param self
* @param string elmName: element name (name attribute)
@@ -329,6 +315,20 @@ angular
}
}
+ /** Get form within scope (if found)
+ * @param self
+ */
+ function getScopeForm(self) {
+ var forms = document.querySelectorAll('form');
+ for (var i = 0; i < forms.length; i++) {
+ var form = document.querySelectorAll('form')[i];
+ if (form && form.name && self.scope[form.name]) {
+ return self.scope[form.name];
+ }
+ }
+ return null;
+ }
+
/** Quick function to find an object inside an array by it's given field name and value, return the index found or -1
* @param Array sourceArray
* @param string searchId: search property id
diff --git a/src/validation-service.js b/src/validation-service.js
index 722c814..4b1511a 100644
--- a/src/validation-service.js
+++ b/src/validation-service.js
@@ -90,26 +90,26 @@ angular
} // addValidator()
/** Is the Form all valid? Loop through Validation Summary to get the answer, if any errors are there then display them and return false
- * @param object Angular Form Object
+ * @param object Angular Form or Scope Object
* @return bool isFormValid
*/
- function checkFormValidity(form) {
+ function checkFormValidity(obj) {
var self = this;
var ctrl, elm, elmName = '', isValid = true;
- if(typeof form === "undefined") {
- throw 'Form validaty checking requires a valid form object passed as argument';
+ if(typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") {
+ throw 'checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).';
}
// loop through $validationSummary and display errors when found on each field
- for(var i = 0, ln = form.$validationSummary.length; i < ln; i++) {
+ for(var i = 0, ln = obj.$validationSummary.length; i < ln; i++) {
isValid = false;
- elmName = form.$validationSummary[i].field;
+ elmName = obj.$validationSummary[i].field;
elm = angular.element(document.querySelector('[name="'+elmName+'"]:not([disabled]):not([ng-disabled]'));
ctrl = angular.element(elm).controller('ngModel');
if(!!elm && elm.length > 0) {
ctrl.$setTouched(); // make the element as it was touched for CSS
- self.commonObj.updateErrorMsg(form.$validationSummary[i].message, {valid: false, elm: elm, submitted: true});
+ self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, {valid: false, elm: elm, submitted: true});
}
}
return isValid;