Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/directives/decorators/bootstrap/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sf-changed="form"
class="form-control {{form.fieldHtmlClass}}"
schema-validate="form"
ng-options="item.value as item.name group by item.group for item in form.titleMap track by item[form.trackBy]"
ng-options="item.value as item.name group by item.group for item in form.titleMap"
name="{{form.key.slice(-1)[0]}}">
</select>
<div class="help-block" sf-message="form.description"></div>
Expand Down
7 changes: 1 addition & 6 deletions src/services/schema-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ angular.module('schemaForm').provider('schemaForm',
return type[0];
}
return type;
};
}

//Creates an default titleMap list from an enum, i.e. a list of strings.
var enumToTitleMap = function(enm) {
Expand Down Expand Up @@ -146,7 +146,6 @@ angular.module('schemaForm').provider('schemaForm',
if (!f.titleMap) {
f.titleMap = enumToTitleMap(schema['enum']);
}
f.trackBy = 'value';
options.lookup[sfPathProvider.stringify(options.path)] = f;
return f;
}
Expand Down Expand Up @@ -340,10 +339,6 @@ angular.module('schemaForm').provider('schemaForm',
obj.titleMap = canonicalTitleMap(obj.titleMap);
}

if(obj.type === 'select') {
obj.trackBy = obj.trackBy || 'value';
}

//
if (obj.itemForm) {
obj.items = [];
Expand Down
79 changes: 0 additions & 79 deletions test/directives/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1649,85 +1649,6 @@ describe('directive',function(){
});


it('should show the correct option selected', function() {
inject(function($compile,$rootScope){
var scope = $rootScope.$new();
scope.thing = { id: 2, a: 1};

scope.schema = {
"type": "object",
"properties": {
"thing": {
"title": "Thing"
}
}
};

scope.form = [{
key: "thing",
type: 'select',
titleMap: [{
name: 'abc', value: { id: 1, a: 2 }
},{
name: 'def', value: { id: 2, a: 1 }
},{
name: 'ghi', value: { id: 3, a: 3 }
}]
}];

var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="thing"></form>');

$compile(tmpl)(scope);
$rootScope.$apply();

setTimeout(function() {
tmpl.children().eq(0).find('select').eq(0).val().should.be.eq(2);
}, 0);

});
});


it('should show the correct option selected with `track by`', function() {
inject(function($compile,$rootScope){
var scope = $rootScope.$new();
scope.thing = { id: 2, a: 1, b: 2 };

scope.schema = {
"type": "object",
"properties": {
"thing": {
"title": "Thing"
}
}
};

scope.form = [{
key: "thing",
type: 'select',
titleMap: [{
id: 1, name: 'abc', value: { id: 1 }
},{
id: 2, name: 'def', value: { id: 2 }
},{
id: 3, name: 'ghi', value: { id: 3 }
}],
trackBy: 'id'
}];

var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="thing"></form>');

$compile(tmpl)(scope);
$rootScope.$apply();

setTimeout(function() {
tmpl.children().eq(0).find('select').eq(0).val().should.be.eq(2);
}, 0);

});
});


it('should update array form on model array ref change',function(){

inject(function($compile,$rootScope){
Expand Down
3 changes: 1 addition & 2 deletions test/services/schema-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ describe('schemaForm', function() {
"name": "NaN",
"value": "NaN"
}
],
"trackBy": "value"
]
},
{
"title": "Are you over 18 years old?",
Expand Down