Skip to content

Commit 70275ad

Browse files
committed
Merge branch 'mike-marcacci-feature/descriptions-in-fieldsets' into development
2 parents 33fbd2a + cf00a4e commit 70275ad

File tree

6 files changed

+59
-49
lines changed

6 files changed

+59
-49
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.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,18 @@ angular.module('schemaForm').provider('schemaForm',
456456

457457
// Takes a titleMap in either object or list format and returns one in
458458
// in the list format.
459-
var canonicalTitleMap = function(titleMap) {
459+
var canonicalTitleMap = function(titleMap, originalEnum) {
460460
if (!angular.isArray(titleMap)) {
461461
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+
}
465471
return canonical;
466472
}
467473
return titleMap;
@@ -502,7 +508,7 @@ angular.module('schemaForm').provider('schemaForm',
502508

503509
//Non standard attributes
504510
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); }
506512
f.schema = schema;
507513

508514
// Ng model options doesn't play nice with undefined, might be defined

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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<fieldset ng-disabled="form.readonly">
22
<legend ng-show="form.title">{{ form.title }}</legend>
3+
<div class="help-block" ng-show="form.description" ng-bind-html="form.description"></div>
34
<div ng-transclude></div>
45
</fieldset>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<fieldset ng-disabled="form.readonly">
22
<legend ng-show="form.title">{{ form.title }}</legend>
3+
<div class="help-block" ng-show="form.description" ng-bind-html="form.description"></div>
34
<sf-decorator ng-repeat="item in form.items" form="item"></sf-decorator>
45
</fieldset>

test/schema-form-test.js

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -62,69 +62,70 @@ describe('Schema form',function(){
6262
});
6363
});
6464

65-
it('should generate html and compile it, deep structure',function(){
65+
it.only('should generate html and compile it, deep structure',function(){
6666

6767
inject(function($compile,$rootScope){
6868
var scope = $rootScope.$new();
6969
scope.person = {};
7070

7171
scope.schema = {
72-
"type": "object",
73-
"properties": {
74-
"name": {
75-
"title": "Name",
76-
"description": "Gimme yea name lad",
77-
"type": "string"
72+
'type': 'object',
73+
'properties': {
74+
'name': {
75+
'title': 'Name',
76+
'description': 'Gimme yea name lad',
77+
'type': 'string'
7878
},
79-
"ianal": {
80-
"type": "boolean",
81-
"title":'IANAL'
79+
'ianal': {
80+
'type': 'boolean',
81+
'title':'IANAL'
8282
},
83-
"age": {
84-
"type": "integer",
85-
"title":'Age',
86-
"minimum": 0
83+
'age': {
84+
'type': 'integer',
85+
'title':'Age',
86+
'minimum': 0
8787
},
88-
"sum": {
89-
"type": "number",
90-
"title": "summa"
88+
'sum': {
89+
'type': 'number',
90+
'title': 'summa'
9191
},
92-
"gender": {
93-
"title": "Choose",
94-
"type": "string",
95-
"enum": [
96-
"undefined",
97-
"null",
98-
"NaN",
92+
'gender': {
93+
'title': 'Choose',
94+
'type': 'string',
95+
'enum': [
96+
'undefined',
97+
'null',
98+
'NaN',
9999
]
100100
},
101-
"attributes": {
102-
"type": "object",
103-
"title": "Attributes",
104-
"required": ['eyecolor'],
105-
"properties": {
106-
"eyecolor": { "type": "string", "title": "Eye color" },
107-
"haircolor": { "type": "string", "title": "Hair color" },
108-
"shoulders": {
109-
"type": "object",
110-
"title": "Shoulders",
111-
"properties": {
112-
"left": { "type": "string" },
113-
"right": { "type": "string" },
101+
'attributes': {
102+
'type': 'object',
103+
'title': 'Attributes',
104+
'required': ['eyecolor'],
105+
'properties': {
106+
'eyecolor': { 'type': 'string', 'title': 'Eye color' },
107+
'haircolor': { 'type': 'string', 'title': 'Hair color' },
108+
'shoulders': {
109+
'type': 'object',
110+
'title': 'Shoulders',
111+
'properties': {
112+
'left': { 'type': 'string' },
113+
'right': { 'type': 'string' },
114114
}
115115
}
116116
}
117117
}
118118
}
119119
};
120120

121-
scope.form = ["*"];
121+
scope.form = ['*'];
122122

123123
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="person" sf-decorator-name="bootstrap-decorator"></form>');
124124

125125
$compile(tmpl)(scope);
126126
$rootScope.$apply();
127127

128+
128129
tmpl.children().length.should.be.equal(6);
129130
tmpl.children().eq(0).children().eq(0).is('div.form-group').should.be.true;
130131
tmpl.children().eq(0).children().eq(0).find('input').is('input[type="text"]').should.be.true;
@@ -145,10 +146,11 @@ describe('Schema form',function(){
145146
tmpl.children().eq(5).children().eq(0).is('fieldset').should.be.true;
146147
tmpl.children().eq(5).children().eq(0).children().eq(0).is('legend').should.be.true;
147148
tmpl.children().eq(5).children().eq(0).children().eq(3).is('sf-decorator').should.be.true;
148-
tmpl.children().eq(5).children().eq(0).children().eq(3).children().eq(0).is('fieldset').should.be.true;
149-
tmpl.children().eq(5).children().eq(0).children().eq(3).children().eq(0).children().length.should.be.eq(3);
150-
tmpl.children().eq(5).children().eq(0).children().eq(3).children().eq(0).find('input[ng-model="model[\'attributes\'][\'shoulders\'][\'left\']"]').length.should.be.eq(1);
151-
tmpl.children().eq(5).children().eq(0).children().eq(3).children().eq(0).find('input[ng-model="model[\'attributes\'][\'shoulders\'][\'right\']"]').length.should.be.eq(1);
149+
150+
tmpl.children().eq(5).children().eq(0).children().eq(4).children().eq(0).is('fieldset').should.be.true;
151+
tmpl.children().eq(5).children().eq(0).children().eq(4).children().eq(0).children().length.should.be.eq(4);
152+
tmpl.children().eq(5).children().eq(0).children().eq(4).children().eq(0).find('input[ng-model="model[\'attributes\'][\'shoulders\'][\'left\']"]').length.should.be.eq(1);
153+
tmpl.children().eq(5).children().eq(0).children().eq(4).children().eq(0).find('input[ng-model="model[\'attributes\'][\'shoulders\'][\'right\']"]').length.should.be.eq(1);
152154

153155
});
154156
});

0 commit comments

Comments
 (0)