Skip to content

Commit 79c2706

Browse files
committed
Updated tests and fixed a bug with checkboxes
1 parent a5cd33f commit 79c2706

File tree

6 files changed

+158
-13
lines changed

6 files changed

+158
-13
lines changed

dist/bootstrap-decorator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/schema-form.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/decorators/bootstrap/checkboxes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="form-group" ng-class="{'has-error': hasError(), 'has-success': hasSuccess()}" ng-init="checkboxValues = {}">
22
<label ng-show="showTitle()">{{form.title}}</label>
3-
<div class="checkbox" ng-repeat="(value,name) in form.titleMap" >
3+
<div class="checkbox" ng-repeat="value in form.schema.items.enum" >
44
<label>
55
<input type="checkbox"
66
sf-changed="form"
77
ng-model="checkboxValues[value]"
88
ng-change="$$value$$ = checkboxValuesToList(checkboxValues)" >
9-
<span ng-bind-html="form.name"></span>
9+
<span ng-bind-html="form.titleMap[value] || value"></span>
1010
</label>
1111

1212
</div>

src/directives/schema-form.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function($compile, schemaForm, schemaFormDecorators, sfSelect){
7474
//FIXME: traverse schema and model and set default values.
7575

7676
var merged = schemaForm.merge(schema,form,ignore);
77-
console.log('merged',merged)
7877
var frag = document.createDocumentFragment();
7978

8079
//make the form available to decorators

src/services/schema-form.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,9 @@ angular.module('schemaForm').provider('schemaForm',[function(){
246246
var service = {};
247247

248248
service.merge = function(schema,form,ignore) {
249-
console.log('to merge',schema,form,ignore);
250249
form = form || ["*"];
251250

252251
var stdForm = service.defaults(schema,ignore);
253-
console.log('standardform',stdForm);
254252

255253
//simple case, we have a "*", just put the stdForm there
256254
var idx = form.indexOf("*");

test/schema-form-test.js

Lines changed: 154 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,7 @@ describe('Schema form',function(){
628628
"type": "string",
629629
"enum": ["foo","bar"]
630630
}
631-
},
632-
"foobars": {
633-
"type": "array"
634-
}
635-
}
631+
} }
636632
};
637633

638634
scope.form = [
@@ -648,7 +644,6 @@ describe('Schema form',function(){
648644
//TODO: more asserts
649645
tmpl.children().length.should.be.equal(2);
650646
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);
652647
});
653648
});
654649

@@ -1013,6 +1008,159 @@ describe('Schema form',function(){
10131008
});
10141009

10151010

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+
10161164

10171165
});
10181166

0 commit comments

Comments
 (0)