Permalink
Browse files

Fixes for modelValue on condition

 * Check for key, might not always be there
 * Use sfPath.stringify on the form.key
  • Loading branch information...
1 parent 95fd452 commit 4dbf111d8291926e23ccf221d6a479e22b49dfd6 @davidlgj davidlgj committed Apr 17, 2015
Showing with 14 additions and 8 deletions.
  1. +4 −3 .jshintrc
  2. +10 −5 src/services/decorators.js
View
@@ -2,14 +2,15 @@
"undef": true,
"unused": true,
"browser": true,
- "globals": {
+ "globals": {
+ "ObjectPath": false,
"console":false,
"jQuery": false,
"$":false,
"assertEquals": false,
"jstestdriver": false,
"assertTrue": false,
- "assertFalse": false,
+ "assertFalse": false,
"describe": false,
"it":false,
"expect": false,
@@ -24,4 +25,4 @@
"Jed": false,
"tws": false
}
-}
+}
@@ -31,8 +31,8 @@ angular.module('schemaForm').provider('schemaFormDecorators',
var createDirective = function(name) {
$compileProvider.directive(name,
- ['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage',
- function($parse, $compile, $http, $templateCache, $interpolate, $q, sfErrorMessage) {
+ ['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage', 'sfPath',
+ function($parse, $compile, $http, $templateCache, $interpolate, $q, sfErrorMessage, sfPath) {
return {
restrict: 'AE',
@@ -204,18 +204,23 @@ angular.module('schemaForm').provider('schemaFormDecorators',
// Do we have a condition? Then we slap on an ng-if on all children,
// but be nice to existing ng-if.
if (form.condition) {
+
+ var evalExpr = 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex})';
+ if (form.key) {
+ evalExpr = 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model' + sfPath.stringify(form.key) + '})';
+ }
+
angular.forEach(element.children(), function(child) {
var ngIf = child.getAttribute('ng-if');
child.setAttribute(
'ng-if',
ngIf ?
'(' + ngIf +
- ') || (evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model["' + form.key.join('"]["') + '"] }))'
- : 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model["' + form.key.join('"]["') + '"] })'
+ ') || (' + evalExpr +')'
+ : evalExpr
);
});
}
-
$compile(element.contents())(scope);
});

0 comments on commit 4dbf111

Please sign in to comment.