Skip to content

Commit d8ed2fc

Browse files
committed
make operators more robust
1 parent 92f3381 commit d8ed2fc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

addon/components/json-form-validate-if/component.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export default Ember.Component.extend({
1111
_operators: Ember.computed(function () {
1212
var operators = this.get('operators');
1313
operators['eq'] = function (a,b) {return String(a)==b; };
14-
operators['has'] = function (a,b) {return a && (a.contains(b) || a.isAny('id', b));};
15-
operators['in'] = function (a,b) {return b.split(',').contains(String(a));};
14+
operators['has'] = function (a,b) {return a && Ember.isArray(a) && (a.contains(b) || a.isAny('id', b));};
15+
operators['in'] = function (a,b) {return b && b.split && b.split(',').contains(String(a));};
1616
operators['not'] = function(a, b) {return a != b;};
17-
operators['has_not'] = function(a, b) {return a && (!a.contains(b) && !a.isAny('id', b));};
17+
operators['has_not'] = function(a, b) {return a && Ember.isArray(a) && (!a.contains(b) && !a.isAny('id', b));};
1818
return operators;
1919
}),
2020

addon/components/json-form/component.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ let ValidationMixin = Ember.Mixin.create({
1818
__operators: {},
1919
_operators: Ember.computed(function () {
2020
var operators = this.get('__operators');
21-
operators['eq'] = function (a,b) {return a==b; };
22-
operators['has'] = function (a,b) {return a && (a.contains(b) || a.isAny('id', b));};
23-
operators['in'] = function (a,b) {return b.split(',').contains(String(a));};
21+
ooperators['eq'] = function (a,b) {return String(a)==b; };
22+
operators['has'] = function (a,b) {return a && Ember.isArray(a) && (a.contains(b) || a.isAny('id', b));};
23+
operators['in'] = function (a,b) {return b && b.split && b.split(',').contains(String(a));};
2424
operators['not'] = function(a, b) {return a != b;};
25-
operators['has_not'] = function(a, b) {return a && (!a.contains(b) && !a.isAny('id', b));};
25+
operators['has_not'] = function(a, b) {return a && Ember.isArray(a) && (!a.contains(b) && !a.isAny('id', b));};
2626
return operators;
2727
}),
2828

0 commit comments

Comments
 (0)