ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [26/50] ignite git commit: IGNITE-843 Fixed unique directive check in case of new item.
Date Wed, 03 Feb 2016 10:56:51 GMT
IGNITE-843 Fixed unique directive check in case of new item.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ff3eb24f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ff3eb24f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ff3eb24f

Branch: refs/heads/ignite-843-rc3
Commit: ff3eb24fd15d2320e36df7e60e9a4fba3521b7bd
Parents: ad450ba
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Tue Feb 2 10:46:41 2016 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Tue Feb 2 10:46:41 2016 +0700

----------------------------------------------------------------------
 .../app/modules/Form/validator/unique.directive.js   | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ff3eb24f/modules/control-center-web/src/main/js/app/modules/Form/validator/unique.directive.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/app/modules/Form/validator/unique.directive.js
b/modules/control-center-web/src/main/js/app/modules/Form/validator/unique.directive.js
index 0d0488e..905a595 100644
--- a/modules/control-center-web/src/main/js/app/modules/Form/validator/unique.directive.js
+++ b/modules/control-center-web/src/main/js/app/modules/Form/validator/unique.directive.js
@@ -21,14 +21,21 @@ export default ['igniteUnique', ['$parse', ($parse) => {
             return;
 
         ngModel.$validators.igniteUnique = (value) => {
-            let idx;
             const arr = $parse(attrs.igniteUnique)(scope);
 
-            // Return true in case if array not exist, array empty, or value is unique.
-            if (!arr || !arr.length || !~(idx = arr.indexOf(value)))
+            // Return true in case if array not exist, array empty.
+            if (!arr || !arr.length)
                 return true;
 
-            return !!(_.isNumber(scope.$index) && scope.$index === idx);
+            const name = attrs.name;
+            const idx = arr.indexOf(value);
+
+            // In case of new element check all items.
+            if (name === 'new')
+                return idx < 0;
+
+            // Check for $index in case of editing in-place.
+            return (_.isNumber(scope.$index) && (idx < 0 || scope.$index === idx));
         };
     };
 


Mime
View raw message