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

Commit 25993a6

Browse files
committed
Fix #151 validation rule "different" makes "required" not enforced
1 parent 060f988 commit 25993a6

File tree

6 files changed

+20
-14
lines changed

6 files changed

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

dist/angular-validation.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* Angular-Validation Directive and Service (ghiscoding)
33
* http://github.com/ghiscoding/angular-validation
44
* @author: Ghislain B.
5-
* @version: 1.5.20
5+
* @version: 1.5.21
66
* @license: MIT
7-
* @build: Thu Apr 20 2017 12:18:09 GMT-0400 (Eastern Daylight Time)
7+
* @build: Sun May 14 2017 23:35:23 GMT-0400 (Eastern Daylight Time)
88
*/
99
/**
1010
* Angular-Validation Directive (ghiscoding)
@@ -949,7 +949,6 @@ angular
949949
var nbValid = 0;
950950
var validator;
951951
var validatedObject = {};
952-
953952
// make an object to hold the message so that we can reuse the object by reference
954953
// in some of the validation check (for example "matching" and "remote")
955954
var validationElmObj = {
@@ -1720,7 +1719,9 @@ angular
17201719
var matchingCtrl = self.ctrl; // keep reference of matching confirmation controller
17211720
var formElmMatchingObj = getFormElementByName(self.ctrl.$name);
17221721

1723-
isValid = (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
1722+
isValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null)
1723+
? false
1724+
: (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
17241725

17251726
// if element to compare against has a friendlyName or if matching 2nd argument was passed, we will use that as a new friendlyName
17261727
// ex.: <input name='input1' friendly-name='Password1'/> :: we would use the friendlyName of 'Password1' not input1
@@ -1734,7 +1735,9 @@ angular
17341735

17351736
// Watch for the parent ngModel, if it change we need to re-validate the child (confirmation)
17361737
self.scope.$watch(parentNgModel, function(newVal, oldVal) {
1737-
var isWatchValid = testCondition(matchingValidator.condition, matchingCtrl.$viewValue, newVal);
1738+
var isWatchValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null)
1739+
? false
1740+
: (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
17381741

17391742
// only inspect on a parent input value change
17401743
if(newVal !== oldVal) {

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.

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.5.20",
3+
"version": "1.5.21",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "dist/angular-validation.min",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Angular Validation (Directive / Service)
2-
`Version: 1.5.20`
2+
`Version: 1.5.21`
33
### Forms Validation with Angular made easy!
44
##### (Concept comes from the amazing Laravel)
55

src/validation-common.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ angular
510510
var nbValid = 0;
511511
var validator;
512512
var validatedObject = {};
513-
514513
// make an object to hold the message so that we can reuse the object by reference
515514
// in some of the validation check (for example "matching" and "remote")
516515
var validationElmObj = {
@@ -1281,7 +1280,9 @@ angular
12811280
var matchingCtrl = self.ctrl; // keep reference of matching confirmation controller
12821281
var formElmMatchingObj = getFormElementByName(self.ctrl.$name);
12831282

1284-
isValid = (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
1283+
isValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null)
1284+
? false
1285+
: (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
12851286

12861287
// if element to compare against has a friendlyName or if matching 2nd argument was passed, we will use that as a new friendlyName
12871288
// ex.: <input name='input1' friendly-name='Password1'/> :: we would use the friendlyName of 'Password1' not input1
@@ -1295,7 +1296,9 @@ angular
12951296

12961297
// Watch for the parent ngModel, if it change we need to re-validate the child (confirmation)
12971298
self.scope.$watch(parentNgModel, function(newVal, oldVal) {
1298-
var isWatchValid = testCondition(matchingValidator.condition, matchingCtrl.$viewValue, newVal);
1299+
var isWatchValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null)
1300+
? false
1301+
: (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue);
12991302

13001303
// only inspect on a parent input value change
13011304
if(newVal !== oldVal) {

0 commit comments

Comments
 (0)