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

Commit 679b24c

Browse files
committed
Throw an error message when name="" is missing
- Throw an error message when user did not provide a `name=""` property inside the element to validate.
1 parent ba30d55 commit 679b24c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

‎angular-validation.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,16 @@
398398
* @param string message: error message to display
399399
*/
400400
var updateErrorMsg = function(message, isFieldValid) {
401+
// Make sure that element has a name="" attribute else it will not work
402+
if(typeof elm.attr('name') === "undefined") {
403+
throw 'Angular-Validation requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="' + elm.attr('ng-model') + '"';
404+
}
405+
401406
// get the name attribute of current element, make sure to strip dirty characters, for example remove a <input name="options[]"/>, we need to strip the "[]"
402407
var elmInputName = elm.attr('name').replace(/[|&;$%@"<>()+,\[\]\{\}]/g, "");
403408
var hasValidation = (typeof isFieldValid === "undefined") ? false : true;
404409
var errorElm = null;
405410

406-
if(typeof elmInputName === "undefined") {
407-
throw 'Angular-Validation requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="' + elm.attr('ng-model') + '"';
408-
}
409-
410411
// find the element which we'll display the error message, this element might be defined by the user with 'validationErrorTo'
411412
if(attrs.hasOwnProperty('validationErrorTo')) {
412413
// validationErrorTo can be used in 3 different ways: with '.' (element error className) or with/without '#' (element error id)

‎readme.md‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ For a smoother user experience, I also added validation on inactivity (timer). S
1111
Now also supporting AngularJS 1.3.x
1212
*current code should work with 1.2.x just the same*
1313

14-
## Requirements
15-
Angular-Validation requires the element that will use validation to have a `name=""` attribute so that it can use this name to associate a `<span>` for error displaying. For example: `<input name="input1" ng-model="input1" validation="validator1" />`.
16-
...* the necessity of name attribute is new since version 1.3.4+, since prior to this change it was asking the user to create his own `<span>` for error displaying.*
17-
1814
## Live Demo
1915
[Plunker](http://plnkr.co/jADq7H)
2016
<a name="live_demo"></a>
2117

18+
## Requirements
19+
Angular-Validation requires the element that will use validation to have a `name=""` attribute, so that it can use this name to associate a `<span>` for error displaying. For example: `<input name="input1" ng-model="input1" validation="validator1" />`.
20+
21+
*the necessity of name attribute is new since version 1.3.4+, since prior to this change it was asking the user to create his own `<span>` for error displaying*
22+
23+
2224
## Some Working Examples
2325
Let's start with a simple example and then let's get down to real business.
2426

@@ -227,16 +229,14 @@ Dependencies:
227229

228230
1. Angular-Translate (https://github.com/PascalPrecht/angular-translate)
229231
2. Bootstrap 3.x *optional* (http://getbootstrap.com/)
230-
3. AngularJS 1.3.x (https://angularjs.org/) see legacy folder for 1.2.x
232+
3. AngularJS 1.2.x / 1.3.x (https://angularjs.org/)
231233

232234
License
233235
-----
234236
[MIT License](http://www.opensource.org/licenses/mit-license.php)
235237

236238
# TODO
237239
#### Any kind of help is welcome from the TODO list
238-
:memo: :point_up:
239-
240240
* Add more validators...
241241
* Add more locale languages... I need your help on that one!!!
242242
* Create an Angular Service that will provide access to attaching validation on the fly from within a controller
@@ -246,4 +246,5 @@ License
246246
* [1.3.1](https://github.com/ghiscoding/angular-validation/commit/44fe9de050504a46bb0eb975c31bc4b0f3b6f516) `2015-01-02` Added Input Match/Confirmation Validator, ex: password confirmation.
247247
* [1.3.2](https://github.com/ghiscoding/angular-validation/commit/41f9ed9abc7a6d66d4ecf6418b810459bf1d8717) `2015-01-03` Float number validator to also permit dot (.) as first character. Also removed keyboard blocking of invalid character on input type="number" now displays error message.
248248
* [1.3.3](https://github.com/ghiscoding/angular-validation/commit/7b3043a97006a3d7043b198f89c91f8b6c49476e) `2015-01-04` Added changelog & updated Bootstrap(3.3.1), AngularJS(1.3.7) to latest versions
249-
* 1.3.4 `2015-01-06` Removed the necessity of creating a `<span>` for displaying the error message, the directive now handles it by itself.
249+
* [1.3.4](https://github.com/ghiscoding/angular-validation/commit/ba30d55ddb8bca44a8032fc8253356450bd4e1d4) `2015-01-06` Removed the necessity of creating a `<span>` for displaying the error message, the directive now handles it by itself.
250+
* [1.3.5]() `2015-01-26` Throw an error message when user did not provide a `name=""` property inside the element to validate.

0 commit comments

Comments
 (0)