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

Commit 84607ca

Browse files
committed
Fix disabled="false" as attribute to run validation
evaluate the disabled="false" attribute value in Angular-Validation so that the validation kicks in when this value is set to "false". This was problem found with the 3rd party library nya-bootstrap-select
1 parent cf135c2 commit 84607ca

File tree

10 files changed

+56
-21
lines changed

10 files changed

+56
-21
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.5.17",
3+
"version": "1.5.18",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Angular-Validation change logs
22

3+
1.5.18 (2017-03-31) Fix disabled="false" as attribute to run validation.
34
1.5.17 (2017-03-10) Add silent mode to checkFormValidity function
45
1.5.16 (2017-01-24) Fix issue where empty Form Controller was throwing an error
56
1.5.15 (2017-01-19) Rename errorMessageVisible flag to isErrorMessageVisible.

dist/angular-validation.min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
5050
<script src="vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
5151

5252
<!-- You can also load angular-validation with the all in 1 minified file -->
53-
<script type="text/javascript" src="dist/angular-validation.min.js"></script>
53+
<!--<script type="text/javascript" src="dist/angular-validation.min.js"></script>-->
5454

5555
<!-- angular-validation, directive and service are totally independent you can load one or the other or you can use them in parallel too. But `-common.js` and `-rules.js` are mandatory. -->
56-
<!--
5756
<script type="text/javascript" src="src/validation-directive.js"></script>
5857
<script type="text/javascript" src="src/validation-service.js"></script>
5958
<script type="text/javascript" src="src/validation-common.js"></script>
6059
<script type="text/javascript" src="src/validation-rules.js"></script>
61-
-->
62-
60+
6361
<!-- your ng-app file -->
6462
<script type="text/javascript" src="app.js"></script>
6563
</div>

more-examples/addon-3rdParty-withScope/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<!-- AngularJS Dropdown MultiSelect -->
5454
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
5555
<script type="text/javascript" src="https://rawgit.com/pc035860/angular-highlightjs/master/angular-highlightjs.js"></script>
56-
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/src/angularjs-dropdown-multiselect.js"></script>
56+
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/dist/angularjs-dropdown-multiselect.min.js"></script>
5757

5858
<!-- AngularJS Multi-Select -->
5959
<script src="https://rawgit.com/isteven/angular-multi-select/master/isteven-multi-select.js"></script>

more-examples/addon-3rdParty/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ <h4><strong>ERRORS!</strong></h4>
119119
<!-- AngularJS Dropdown MultiSelect -->
120120
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
121121
<script type="text/javascript" src="https://rawgit.com/pc035860/angular-highlightjs/master/angular-highlightjs.js"></script>
122-
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/src/angularjs-dropdown-multiselect.js"></script>
122+
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/dist/angularjs-dropdown-multiselect.min.js"></script>
123123

124124
<!-- AngularJS Multi-Select -->
125125
<script src="https://rawgit.com/isteven/angular-multi-select/master/isteven-multi-select.js"></script>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.5.17",
3+
"version": "1.5.18",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "dist/angular-validation.min",

src/validation-common.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ angular
153153
// also save it inside controllerAs form (if found)
154154
if (!!form && !!form.$name) {
155155
var formName = form.$name.indexOf('.') >= 0 ? form.$name.split('.')[1] : form.$name;
156-
var ctrlForm = (!!_globalOptions.controllerAs && !!_globalOptions.controllerAs[formName])
157-
? _globalOptions.controllerAs[formName]
156+
var ctrlForm = (!!_globalOptions.controllerAs && !!_globalOptions.controllerAs[formName])
157+
? _globalOptions.controllerAs[formName]
158158
: ((typeof self.elm.controller() !== "undefined") ? self.elm.controller()[formName] : null);
159-
159+
160160
if(!!ctrlForm) {
161161
ctrlForm.$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name);
162162
}
@@ -542,9 +542,22 @@ angular
542542
validator = validatorAutoDetectType(validator, strValue);
543543
}
544544

545-
// get the ngDisabled attribute if found
545+
// get the disabled & ngDisabled attributes if found
546+
var elmAttrDisabled = self.elm.prop("disabled");
546547
var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled;
547548

549+
var isDisabled = (elmAttrDisabled === "")
550+
? true
551+
: (typeof elmAttrDisabled === "boolean")
552+
? elmAttrDisabled
553+
: (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false;
554+
555+
var isNgDisabled = (elmAttrNgDisabled === "")
556+
? true
557+
: (typeof elmAttrNgDisabled === "boolean")
558+
? elmAttrNgDisabled
559+
: (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false;
560+
548561
// now that we have a Validator type, we can now validate our value
549562
// there is multiple type that can influence how the value will be validated
550563
switch(validator.type) {
@@ -569,7 +582,7 @@ angular
569582
}
570583

571584
// not required and not filled is always valid & 'disabled', 'ng-disabled' elements should always be valid
572-
if ((!self.bFieldRequired && !strValue && !_validateOnEmpty) || (!!self.elm.prop("disabled") || !!self.scope.$eval(elmAttrNgDisabled))) {
585+
if ((!self.bFieldRequired && !strValue && !_validateOnEmpty) || (isDisabled || isNgDisabled)) {
573586
isConditionValid = true;
574587
}
575588

@@ -1404,9 +1417,22 @@ angular
14041417

14051418
// get the ngDisabled attribute if found
14061419
var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled;
1420+
var elmAttrDisabled = self.elm.prop("disabled");
1421+
1422+
var isDisabled = (elmAttrDisabled === "")
1423+
? true
1424+
: (typeof elmAttrDisabled === "boolean")
1425+
? elmAttrDisabled
1426+
: (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false;
1427+
1428+
var isNgDisabled = (elmAttrNgDisabled === "")
1429+
? true
1430+
: (typeof elmAttrNgDisabled === "boolean")
1431+
? elmAttrNgDisabled
1432+
: (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false;
14071433

14081434
// a 'disabled' element should always be valid, there is no need to validate it
1409-
if (!!self.elm.prop("disabled") || !!self.scope.$eval(elmAttrNgDisabled)) {
1435+
if (isDisabled || isNgDisabled) {
14101436
isValid = true;
14111437
} else {
14121438
// before running Regex test, we'll make sure that an input of type="number" doesn't hold invalid keyboard chars, if true skip Regex

src/validation-directive.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@
4848
// watch the `disabled` attribute for changes
4949
// if it become disabled then skip validation else it becomes enable then we need to revalidate it
5050
attrs.$observe("disabled", function(disabled) {
51-
if (disabled) {
51+
var isDisabled = (disabled === "")
52+
? true
53+
: (typeof disabled === "boolean") ? disabled
54+
: (typeof disabled !== "undefined") ? scope.$eval(disabled) : false;
55+
56+
if (isDisabled === true) {
5257
// Turn off validation when element is disabled & remove it from validation summary
5358
cancelValidation();
5459
commonObj.removeFromValidationSummary(_elmName);

src/validation-service.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,12 @@ angular
547547
// use a timeout so that the digest of removing the `disabled` attribute on the DOM is completed
548548
// because commonObj.validate() checks for both the `disabled` and `ng-disabled` attribute so it basically fails without the $timeout because of the digest
549549
$timeout(function() {
550-
if (disabled) {
550+
var isDisabled = (disabled === "")
551+
? true
552+
: (typeof disabled === "boolean") ? disabled
553+
: (typeof disabled !== "undefined") ? scope.$eval(disabled) : false;
554+
555+
if (isDisabled) {
551556
// Remove it from validation summary
552557
attrs.ctrl.$setValidity('validation', true);
553558
self.commonObj.updateErrorMsg('', { isValid: true, obj: formElmObj });

0 commit comments

Comments
 (0)