@@ -666,27 +666,20 @@ function orEmptyArray(v) {
666
666
} ;
667
667
668
668
} ;
669
-
670
669
function applyIncludeExclude ( metadata , outputModel , dataModelItem , initialConstraints ) {
671
670
var path = metadata . constraints . excludePath || metadata . constraints . includePath ;
672
671
673
672
var currentValue = dataModelItem ( ) ;
674
- var selectedSoFar = [ ] ;
675
- outputModel . eachValueForPath ( path , function ( val ) {
676
- if ( _ . isArray ( val ) ) {
677
- selectedSoFar = selectedSoFar . concat ( val ) ;
678
- } else if ( val != null ) {
679
- selectedSoFar . push ( val ) ;
680
- }
681
- } ) ;
673
+ var selectedSoFar = outputModel . getModelValuesForPath ( path ) ;
682
674
683
675
if ( metadata . constraints . excludePath ) {
684
676
var filteredConstraints = _ . filter ( initialConstraints , function ( value ) {
685
677
// Handle object valued constraints - however the functions are attached after the first call to
686
678
// the computed observable, so we need to guard against that.
687
- value = _ . isFunction ( dataModelItem . constraints . value ) ? dataModelItem . constraints . value ( value ) : value ;
679
+ value = _ . isFunction ( dataModelItem . constraintValue ) ? dataModelItem . constraintValue ( value ) : value ;
688
680
var isCurrentSelection = _ . isArray ( currentValue ) ? currentValue . indexOf ( value ) >= 0 : value == currentValue ;
689
- return ( isCurrentSelection || selectedSoFar . indexOf ( value ) < 0 ) ;
681
+ var include = ( isCurrentSelection || selectedSoFar . indexOf ( value ) < 0 ) ;
682
+ return include ;
690
683
} ) ;
691
684
return filteredConstraints ;
692
685
} else {
@@ -703,9 +696,7 @@ function orEmptyArray(v) {
703
696
704
697
return constraints ;
705
698
}
706
-
707
699
}
708
-
709
700
/**
710
701
* Implements the constraints specified on a single data model item using the "constraints" attribute in the metadata.
711
702
* Also provides access to global configuration and context for components that need it.
@@ -780,7 +771,20 @@ function orEmptyArray(v) {
780
771
valueProperty = metadata . constraints . valueProperty || valueProperty ;
781
772
textProperty = metadata . constraints . textProperty || textProperty ;
782
773
}
783
-
774
+ // These need to be defined before the computed constraint is defined to support correct evaluation
775
+ // of the excludePath function.
776
+ self . constraintValue = function ( constraint ) {
777
+ if ( _ . isObject ( constraint ) ) {
778
+ return constraint [ valueProperty ] ;
779
+ }
780
+ return constraint ;
781
+ } ;
782
+ self . constraintText = function ( constraint ) {
783
+ if ( _ . isObject ( constraint ) ) {
784
+ return constraint [ textProperty ] ;
785
+ }
786
+ return constraint ;
787
+ } ;
784
788
self . constraints = [ ] ;
785
789
var includeExcludeDefined = metadata . constraints . excludePath || metadata . constraints . includePath ;
786
790
// Support existing configuration style.
@@ -835,18 +839,8 @@ function orEmptyArray(v) {
835
839
}
836
840
}
837
841
838
- self . constraints . value = function ( constraint ) {
839
- if ( _ . isObject ( constraint ) ) {
840
- return constraint [ valueProperty ] ;
841
- }
842
- return constraint ;
843
- } ;
844
- self . constraints . text = function ( constraint ) {
845
- if ( _ . isObject ( constraint ) ) {
846
- return constraint [ textProperty ] ;
847
- }
848
- return constraint ;
849
- } ;
842
+ self . constraints . value = self . constraintValue ;
843
+ self . constraints . text = self . constraintText ;
850
844
self . constraints . label = function ( value ) {
851
845
852
846
if ( ! value && ko . isObservable ( self ) ) {
@@ -1272,6 +1266,24 @@ function orEmptyArray(v) {
1272
1266
self . iterateOverPath ( pathAsArray , callback , self . data ) ;
1273
1267
}
1274
1268
1269
+ /**
1270
+ * Iterates over every instance of the DataModelItem defined by path and returns an array containing
1271
+ * the values found at each item.
1272
+ * @param path the path to the data model item of interest (e.g. list.nestedList.textValue1)
1273
+ * @returns {*[] }
1274
+ */
1275
+ self . getModelValuesForPath = function ( path ) {
1276
+ var values = [ ] ;
1277
+ self . eachValueForPath ( path , function ( val ) {
1278
+ if ( _ . isArray ( val ) ) {
1279
+ values = values . concat ( val ) ;
1280
+ } else if ( val != null ) {
1281
+ values . push ( val ) ;
1282
+ }
1283
+ } ) ;
1284
+ return values ;
1285
+ }
1286
+
1275
1287
/**
1276
1288
* Recursively iterates over each element in the supplied pathAsArray, taking into
1277
1289
* account when values are lists.
0 commit comments