gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

select options w/ numerical values represented as string #209

Closed benmonro closed 8 years ago

benmonro commented 8 years ago

I have in my form a select box for a list of time zones. The timezones are represented in our code using an array of arrays in order to ensure the order of the timezones is properly displayed.

timeZones = [
    ['', '--'],
    ['20', '(UTC-12:00) International Date Line West'],
    ['56', '(UTC+13:00) Samoa'],
    ['34', '(UTC-10:00) Hawaii'],
    ['1', '(UTC-09:00) Alaska'],
    ['50', '(UTC-08:00) Pacific Time (US & Canada)'],
    ['41', '(UTC-07:00) Mountain Time (US & Canada)']
];

It seems that t.enums expects things to be in a map format. However when I convert this array into a map, the order of the options is then sorted by the numerical value. Is there a way to work around this so that the order is preserved?

benmonro commented 8 years ago

My work around was to prepend the keys with 'tz' and then add a transformer to the field. Not the best solution. Are there any other options?

benmonro commented 8 years ago

Just realized I can set the options in the UI rather than setting them in the enum in the model.