Skip to content

Commit 4dbf111

Browse files
committed
Fixes for modelValue on condition
* Check for key, might not always be there * Use sfPath.stringify on the form.key
1 parent 95fd452 commit 4dbf111

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

.jshintrc

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"undef": true,
33
"unused": true,
44
"browser": true,
5-
"globals": {
5+
"globals": {
6+
"ObjectPath": false,
67
"console":false,
78
"jQuery": false,
89
"$":false,
910
"assertEquals": false,
1011
"jstestdriver": false,
1112
"assertTrue": false,
12-
"assertFalse": false,
13+
"assertFalse": false,
1314
"describe": false,
1415
"it":false,
1516
"expect": false,
@@ -24,4 +25,4 @@
2425
"Jed": false,
2526
"tws": false
2627
}
27-
}
28+
}

src/services/decorators.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ angular.module('schemaForm').provider('schemaFormDecorators',
3131

3232
var createDirective = function(name) {
3333
$compileProvider.directive(name,
34-
['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage',
35-
function($parse, $compile, $http, $templateCache, $interpolate, $q, sfErrorMessage) {
34+
['$parse', '$compile', '$http', '$templateCache', '$interpolate', '$q', 'sfErrorMessage', 'sfPath',
35+
function($parse, $compile, $http, $templateCache, $interpolate, $q, sfErrorMessage, sfPath) {
3636

3737
return {
3838
restrict: 'AE',
@@ -204,18 +204,23 @@ angular.module('schemaForm').provider('schemaFormDecorators',
204204
// Do we have a condition? Then we slap on an ng-if on all children,
205205
// but be nice to existing ng-if.
206206
if (form.condition) {
207+
208+
var evalExpr = 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex})';
209+
if (form.key) {
210+
evalExpr = 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model' + sfPath.stringify(form.key) + '})';
211+
}
212+
207213
angular.forEach(element.children(), function(child) {
208214
var ngIf = child.getAttribute('ng-if');
209215
child.setAttribute(
210216
'ng-if',
211217
ngIf ?
212218
'(' + ngIf +
213-
') || (evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model["' + form.key.join('"]["') + '"] }))'
214-
: 'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex, "modelValue": model["' + form.key.join('"]["') + '"] })'
219+
') || (' + evalExpr +')'
220+
: evalExpr
215221
);
216222
});
217223
}
218-
219224
$compile(element.contents())(scope);
220225
});
221226

0 commit comments

Comments
 (0)