Skip to content

Commit 24c8796

Browse files
committed
Maintain enum order in select options #82
1 parent 204d5bb commit 24c8796

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/services/schema-form.js

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

1818
// Takes a titleMap in either object or list format and returns one in
1919
// in the list format.
20-
var canonicalTitleMap = function(titleMap) {
20+
var canonicalTitleMap = function(titleMap, originalEnum) {
2121
if (!angular.isArray(titleMap)) {
2222
var canonical = [];
23-
angular.forEach(titleMap, function(name, value) {
24-
canonical.push({name: name, value: value});
25-
});
23+
if (originalEnum) {
24+
angular.forEach(originalEnum, function(value, index) {
25+
canonical.push({name: titleMap[value], value: value});
26+
});
27+
} else {
28+
angular.forEach(titleMap, function(name, value) {
29+
canonical.push({name: name, value: value});
30+
});
31+
}
2632
return canonical;
2733
}
2834
return titleMap;
@@ -63,7 +69,7 @@ angular.module('schemaForm').provider('schemaForm',
6369

6470
//Non standard attributes
6571
if (schema.validationMessage) { f.validationMessage = schema.validationMessage; }
66-
if (schema.enumNames) { f.titleMap = canonicalTitleMap(schema.enumNames); }
72+
if (schema.enumNames) { f.titleMap = canonicalTitleMap(schema.enumNames, schema.enum); }
6773
f.schema = schema;
6874

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

0 commit comments

Comments
 (0)