Closed
Description
Is it possible to have the dropdowns sorted in alphabetical order?
I have some enumeration mapping 'object' which I have. I loop through this and if it has an enum which matches a field i have, then it assigns the enum mapping to the formDefinition fields titleMap.
populateFormDefinition : function(formDefinition, enums){
_.forEach(formDefinition,function(formElementMeta,columnIndex){
_.forEach(formDefinition[columnIndex],function(formElementMeta,rowIndex){
if(typeof(enums[formElementMeta.key]) !== 'undefined' ){
formDefinition[columnIndex][rowIndex].titleMap = enums[formElementMeta.key];
}
});
});
},
If you debug and inspect the titleMap, it's in order, e.g.
'a' : 'a'
'b' : 'b' ....
However, when it is rendered onthe screen, it seems to be in a random order?
Is this a bug or am I doing something wrong, can anyone advise please?
Thanks.
Also while I'm here - is there a way to have an empty dropdown value - so that you can 'unselect' a value.....I could simply add a blank mapping to the titlemap, i.e. '':'' but is there a more elegent solution?
Activity
davidlgj commentedon Apr 1, 2015
Do you use the object or the array form of the
titleMap
?PhilBroadbent commentedon Apr 1, 2015
object.
e.g. enums[formElementMeta.key] could be:
Object
"": ""
AP: "Asia Pacific"
EM: "EMEA"
GL: "Global"
NA: "North America"
proto: Object
davidlgj commentedon Apr 1, 2015
Ok, it should be in the object order, but since object order is not guaranteed in javascript I'll recommend you use the array syntax for the titleMap (the object syntax is there for JSON Form compatability). I wonder if this popped up when we changed from a
ng-repeat
of options to anng-options
... Anyways, I'm in the process of merging #294 and that will solve the "empty" option problem for you next release.PhilBroadbent commentedon Apr 1, 2015
Ahh nice! I thought it would have to be an array of strings, but I've just looked at docs and its an array of objects, I will try this out in the morning, thanks a lot!
I must say I love this project - the documentation is great and the team is so quick to resond, thank you!
I'll leave this open for now, and providing it works I'll close it in morning.
PhilBroadbent commentedon Apr 2, 2015
Okay so if anyone else has this - you should use array of objects containing single value/name pair, rather than just object containing many mappings. (See my above object I used). To convert this object into a sorted array of objects I did this:
Thanks David for pointing this out.