@@ -628,11 +628,7 @@ describe('Schema form',function(){
628
628
"type" : "string" ,
629
629
"enum" : [ "foo" , "bar" ]
630
630
}
631
- } ,
632
- "foobars" : {
633
- "type" : "array"
634
- }
635
- }
631
+ } }
636
632
} ;
637
633
638
634
scope . form = [
@@ -648,7 +644,6 @@ describe('Schema form',function(){
648
644
//TODO: more asserts
649
645
tmpl . children ( ) . length . should . be . equal ( 2 ) ;
650
646
tmpl . children ( ) . eq ( 0 ) . find ( 'input[type=checkbox]' ) . length . should . be . eq ( 2 ) ;
651
- tmpl . children ( ) . eq ( 1 ) . find ( 'input[type=checkbox]' ) . length . should . be . eq ( 2 ) ;
652
647
} ) ;
653
648
} ) ;
654
649
@@ -1013,6 +1008,159 @@ describe('Schema form',function(){
1013
1008
} ) ;
1014
1009
1015
1010
1011
+ it ( 'should render a list of subforms when schema type is array' , function ( ) {
1012
+
1013
+ inject ( function ( $compile , $rootScope ) {
1014
+ var scope = $rootScope . $new ( ) ;
1015
+ scope . person = { } ;
1016
+
1017
+ scope . schema = {
1018
+ "type" : "object" ,
1019
+ "properties" : {
1020
+ "names" : {
1021
+ "type" : "array" ,
1022
+ "items" : {
1023
+ "type" : "string" ,
1024
+ "title" : "Name"
1025
+ }
1026
+ } ,
1027
+ "subforms" : {
1028
+ "type" : "array" ,
1029
+ "items" : {
1030
+ "type" : "object" ,
1031
+ "title" : "subform" ,
1032
+ "properties" : {
1033
+ "one" : { "type" : "string" } ,
1034
+ "two" : { "type" : "number" , "title" : "Two" }
1035
+ }
1036
+ }
1037
+ } ,
1038
+ "subsubforms" : {
1039
+ "type" : "array" ,
1040
+ "items" : {
1041
+ "type" : "object" ,
1042
+ "title" : "subform" ,
1043
+ "properties" : {
1044
+ "one" : { "type" : "string" } ,
1045
+ "list" : {
1046
+ "type" : "array" ,
1047
+ "items" : {
1048
+ "type" : "number" ,
1049
+ "title" : "sublist numbers"
1050
+ }
1051
+ }
1052
+ }
1053
+ }
1054
+ }
1055
+ }
1056
+ } ;
1057
+
1058
+ scope . form = [
1059
+ "names" ,
1060
+ {
1061
+ key : "subforms" ,
1062
+ type : "array" ,
1063
+ items : [
1064
+ "subforms[].one"
1065
+ ]
1066
+ } ,
1067
+ "subsubforms"
1068
+ ] ;
1069
+
1070
+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
1071
+
1072
+ $compile ( tmpl ) ( scope ) ;
1073
+ $rootScope . $apply ( ) ;
1074
+
1075
+ //TODO: more asserts
1076
+ tmpl . children ( ) . length . should . be . equal ( 3 ) ;
1077
+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . length . should . be . eq ( 1 ) ;
1078
+ tmpl . children ( ) . eq ( 0 ) . find ( 'button' ) . length . should . be . eq ( 2 ) ;
1079
+ tmpl . children ( ) . eq ( 0 ) . find ( 'button' ) . eq ( 1 ) . text ( ) . trim ( ) . should . be . eq ( 'Add' ) ;
1080
+
1081
+ tmpl . children ( ) . eq ( 1 ) . find ( 'input' ) . length . should . be . eq ( 1 ) ;
1082
+ tmpl . children ( ) . eq ( 1 ) . find ( 'fieldset' ) . length . should . be . eq ( 0 ) ;
1083
+ tmpl . children ( ) . eq ( 1 ) . find ( 'button' ) . length . should . be . eq ( 2 ) ;
1084
+ tmpl . children ( ) . eq ( 1 ) . find ( 'button' ) . eq ( 1 ) . text ( ) . trim ( ) . should . be . eq ( 'Add' ) ;
1085
+
1086
+ tmpl . children ( ) . eq ( 2 ) . find ( 'input' ) . length . should . be . eq ( 2 ) ;
1087
+ tmpl . children ( ) . eq ( 2 ) . find ( 'fieldset' ) . length . should . be . eq ( 1 ) ;
1088
+ tmpl . children ( ) . eq ( 2 ) . find ( 'button' ) . length . should . be . eq ( 4 ) ;
1089
+ tmpl . children ( ) . eq ( 2 ) . find ( 'button' ) . eq ( 3 ) . text ( ) . trim ( ) . should . be . eq ( 'Add' ) ;
1090
+
1091
+
1092
+ } ) ;
1093
+ } ) ;
1094
+
1095
+ it ( 'should render a tabarray of subforms when asked' , function ( ) {
1096
+
1097
+ inject ( function ( $compile , $rootScope ) {
1098
+ var scope = $rootScope . $new ( ) ;
1099
+ scope . person = {
1100
+ names : [ 'me' , 'you' , 'another' ]
1101
+ } ;
1102
+
1103
+ scope . schema = {
1104
+ "type" : "object" ,
1105
+ "properties" : {
1106
+ "names" : {
1107
+ "type" : "array" ,
1108
+ "items" : {
1109
+ "type" : "string" ,
1110
+ "title" : "Name"
1111
+ }
1112
+ } ,
1113
+ "subforms" : {
1114
+ "type" : "array" ,
1115
+ "items" : {
1116
+ "type" : "object" ,
1117
+ "title" : "subform" ,
1118
+ "properties" : {
1119
+ "one" : { "type" : "string" } ,
1120
+ "two" : { "type" : "number" , "title" : "Two" }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+ } ;
1126
+
1127
+ scope . form = [
1128
+ { key : "names" , type : "tabarray" } ,
1129
+ {
1130
+ key : "subforms" ,
1131
+ type : "tabarray" ,
1132
+ tabType : "right" ,
1133
+ items : [
1134
+ "subforms[].one"
1135
+ ]
1136
+ }
1137
+ ] ;
1138
+
1139
+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
1140
+
1141
+ $compile ( tmpl ) ( scope ) ;
1142
+ $rootScope . $apply ( ) ;
1143
+
1144
+ //TODO: more asserts
1145
+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
1146
+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . length . should . be . eq ( 3 ) ;
1147
+ tmpl . children ( ) . eq ( 0 ) . find ( 'button' ) . length . should . be . eq ( 3 ) ;
1148
+ tmpl . children ( ) . eq ( 0 ) . find ( 'button' ) . eq ( 0 ) . text ( ) . trim ( ) . should . be . eq ( 'Remove' ) ;
1149
+ tmpl . children ( ) . eq ( 0 ) . is ( 'div' ) . should . be . true ;
1150
+ tmpl . children ( ) . eq ( 0 ) . attr ( 'sf-array' ) . should . be . thruthy ;
1151
+ tmpl . children ( ) . eq ( 0 ) . find ( '.tabs-left' ) . length . should . be . eq ( 1 ) ;
1152
+
1153
+ tmpl . children ( ) . eq ( 1 ) . find ( 'input' ) . length . should . be . eq ( 1 ) ;
1154
+ tmpl . children ( ) . eq ( 1 ) . find ( 'fieldset' ) . length . should . be . eq ( 0 ) ;
1155
+ tmpl . children ( ) . eq ( 1 ) . find ( 'button' ) . length . should . be . eq ( 1 ) ;
1156
+ tmpl . children ( ) . eq ( 1 ) . find ( 'button' ) . text ( ) . trim ( ) . should . be . eq ( 'Remove' ) ;
1157
+ tmpl . children ( ) . eq ( 1 ) . attr ( 'sf-array' ) . should . be . thruthy ;
1158
+ tmpl . children ( ) . eq ( 1 ) . find ( '.tabs-left' ) . length . should . be . eq ( 0 ) ;
1159
+ tmpl . children ( ) . eq ( 1 ) . find ( '.tabs-right' ) . length . should . be . eq ( 1 ) ;
1160
+
1161
+ } ) ;
1162
+ } ) ;
1163
+
1016
1164
1017
1165
} ) ;
1018
1166
0 commit comments