enhancement
major
minor
major
minor
minor
#29874
TL Views: a select input always sorts its options by label - no way to keep the order of the option list
tl-layout-view 8.0.0-alpha10, com.top_logic.layout.view.form.SelectControlProvider.
Problem
SelectControlProvider.createControl always hands ReactDropdownSelectControl a LabelComparator.newCachingInstance(...); its configuration has no option to keep the order of the options. Options with a natural order that is not alphabetical come out sorted by label.
In E-Home the group monitor's choice of the day of the week (options computed by a TL-Script function in the order "No day", Monday ... Sunday) shows "Dienstag, Donnerstag, Freitag, Kein Tag, Mittwoch, Montag, Samstag, Sonntag"; the same for the step sizes "1: 100 %" ... "7: 1.56 %" and enumeration values.
Reproduction
<value-input value="day" options="d -> ['No day', 'Monday', 'Tuesday', 'Wednesday']"> <input-control class="com.top_logic.layout.view.form.SelectControlProvider"/> </value-input>
shows Monday, No day, Tuesday, Wednesday.
Expected
A setting on the select (e.g. sorted="false" / an option order "as given"), or the rule of the classic SelectField (#3546): sort only when a comparator is configured explicitly, keep the order of the option list otherwise.
Workaround in E-Home
de.haumacher.ehome.view.OptionOrderSelectControlProvider, a SelectControlProvider that passes no comparator; recorded in doc/tl-todo.md.
Lösung
The order of the options is decided by the option source, as in the classic form layer, and can be overridden per field on the select control:
- FieldSpec (tl-layout-react) carries the option order the field asks for: a Comparator, null meaning "as given" - alongside the select display and orientation it already carries.
- AttributeOptions.orderFor(part) (tl-layout-view) answers it for a model attribute, mirroring the option resolution: an options annotation answers through its Generator.getOptionOrder() (so alphabetical-order of options-by-expression keeps working), an enumeration and an enum datatype keep their order, a reference and a configured OptionProvider (country, language, time zone) sort by label. FieldControlService puts it on the attribute's field spec.
- A <value-input> with an options expression or an enumeration value type offers the options as given; a reference value type sorts by label.
- SelectControlProvider gets the configuration option order with the values by-label and as-given; unset, the field decides (the same pattern as display and orientation).
With that, the reproduction above shows "No day, Monday, Tuesday, Wednesday" without any configuration, and <input-control class="...SelectControlProvider" order="by-label"/> restores an alphabetical list where wanted.