@@ -456,12 +456,18 @@ angular.module('schemaForm').provider('schemaForm',
456
456
457
457
// Takes a titleMap in either object or list format and returns one in
458
458
// in the list format.
459
- var canonicalTitleMap = function ( titleMap ) {
459
+ var canonicalTitleMap = function ( titleMap , originalEnum ) {
460
460
if ( ! angular . isArray ( titleMap ) ) {
461
461
var canonical = [ ] ;
462
- angular . forEach ( titleMap , function ( name , value ) {
463
- canonical . push ( { name : name , value : value } ) ;
464
- } ) ;
462
+ if ( originalEnum ) {
463
+ angular . forEach ( originalEnum , function ( value , index ) {
464
+ canonical . push ( { name : titleMap [ value ] , value : value } ) ;
465
+ } ) ;
466
+ } else {
467
+ angular . forEach ( titleMap , function ( name , value ) {
468
+ canonical . push ( { name : name , value : value } ) ;
469
+ } ) ;
470
+ }
465
471
return canonical ;
466
472
}
467
473
return titleMap ;
@@ -502,7 +508,7 @@ angular.module('schemaForm').provider('schemaForm',
502
508
503
509
//Non standard attributes
504
510
if ( schema . validationMessage ) { f . validationMessage = schema . validationMessage ; }
505
- if ( schema . enumNames ) { f . titleMap = canonicalTitleMap ( schema . enumNames ) ; }
511
+ if ( schema . enumNames ) { f . titleMap = canonicalTitleMap ( schema . enumNames , schema . enum ) ; }
506
512
f . schema = schema ;
507
513
508
514
// Ng model options doesn't play nice with undefined, might be defined
@@ -658,8 +664,9 @@ angular.module('schemaForm').provider('schemaForm',
658
664
/**
659
665
* Provider API
660
666
*/
661
- this . defaults = defaults ;
662
- this . stdFormObj = stdFormObj ;
667
+ this . defaults = defaults ;
668
+ this . stdFormObj = stdFormObj ;
669
+ this . defaultFormDefinition = defaultFormDefinition ;
663
670
664
671
/**
665
672
* Register a post process function.
@@ -718,7 +725,6 @@ angular.module('schemaForm').provider('schemaForm',
718
725
options = options || { } ;
719
726
720
727
var stdForm = service . defaults ( schema , ignore , options ) ;
721
-
722
728
//simple case, we have a "*", just put the stdForm there
723
729
var idx = form . indexOf ( '*' ) ;
724
730
if ( idx !== - 1 ) {
@@ -738,11 +744,29 @@ angular.module('schemaForm').provider('schemaForm',
738
744
obj = { key : obj } ;
739
745
}
740
746
747
+ if ( obj . key ) {
748
+ if ( typeof obj . key === 'string' ) {
749
+ obj . key = sfPathProvider . parse ( obj . key ) ;
750
+ }
751
+ }
752
+
741
753
//If it has a titleMap make sure it's a list
742
754
if ( obj . titleMap ) {
743
755
obj . titleMap = canonicalTitleMap ( obj . titleMap ) ;
744
756
}
745
757
758
+ //
759
+ if ( obj . itemForm ) {
760
+ obj . items = [ ] ;
761
+ var str = sfPathProvider . stringify ( obj . key ) ;
762
+ var stdForm = lookup [ str ] ;
763
+ angular . forEach ( stdForm . items , function ( item ) {
764
+ var o = angular . copy ( obj . itemForm ) ;
765
+ o . key = item . key ;
766
+ obj . items . push ( o ) ;
767
+ } ) ;
768
+ }
769
+
746
770
//if it's a type with items, merge 'em!
747
771
if ( obj . items ) {
748
772
obj . items = service . merge ( schema , obj . items , ignore ) ;
@@ -757,10 +781,6 @@ angular.module('schemaForm').provider('schemaForm',
757
781
758
782
//extend with std form from schema.
759
783
if ( obj . key ) {
760
- if ( typeof obj . key === 'string' ) {
761
- obj . key = sfPathProvider . parse ( obj . key ) ;
762
- }
763
-
764
784
var str = sfPathProvider . stringify ( obj . key ) ;
765
785
if ( lookup [ str ] ) {
766
786
obj = angular . extend ( lookup [ str ] , obj ) ;
@@ -789,7 +809,7 @@ angular.module('schemaForm').provider('schemaForm',
789
809
if ( schema . type === 'object' ) {
790
810
angular . forEach ( schema . properties , function ( v , k ) {
791
811
if ( ignore [ k ] !== true ) {
792
- var required = schema . required && schema . required . indexOf ( k [ k . length - 1 ] ) !== - 1 ;
812
+ var required = schema . required && schema . required . indexOf ( k ) !== - 1 ;
793
813
var def = defaultFormDefinition ( k , v , {
794
814
path : [ k ] , // Path to this property in bracket notation.
795
815
lookup : lookup , // Extra map to register with. Optimization for merger.
@@ -1019,6 +1039,7 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
1019
1039
if ( scope . validateArray ) {
1020
1040
scope . validateArray ( ) ;
1021
1041
}
1042
+ return list ;
1022
1043
} ;
1023
1044
1024
1045
// Always start with one empty form unless configured otherwise.
@@ -1178,7 +1199,8 @@ angular.module('schemaForm')
1178
1199
scope : {
1179
1200
schema : '=sfSchema' ,
1180
1201
initialForm : '=sfForm' ,
1181
- model : '=sfModel'
1202
+ model : '=sfModel' ,
1203
+ options : '=sfOptions'
1182
1204
} ,
1183
1205
controller : [ '$scope' , function ( $scope ) {
1184
1206
this . evalInParentScope = function ( expr , locals ) {
@@ -1231,10 +1253,7 @@ angular.module('schemaForm')
1231
1253
lastDigest . schema = schema ;
1232
1254
lastDigest . form = form ;
1233
1255
1234
- // Check for options
1235
- var options = scope . $eval ( attrs . sfOptions ) ;
1236
-
1237
- var merged = schemaForm . merge ( schema , form , ignore , options ) ;
1256
+ var merged = schemaForm . merge ( schema , form , ignore , scope . options ) ;
1238
1257
var frag = document . createDocumentFragment ( ) ;
1239
1258
1240
1259
//make the form available to decorators
0 commit comments