I learned something interesting today about how multi-select listbox TVs behave. They store the multiple values in the order that you select them (I knew that part already). BUT - when you go to edit a resource that has an existing list of values in a TV of this type, they will not be rendered in the order they were stored in - they will be rendered according to the alphabetical sort order rules that dictate how the TV's master list of values are displayed.
What this means, in practical terms, is that if the order of selected items in a multi-select TV is important to you, you will need to manually re-order the items before each time you save the resource - otherwise they will be re-ordered alphabetically.
Example:
My multi-select TV has the following list of options to choose from:
- aardvark
- bird
- cat
- dog
- elephant
- ferret
If I edit a resource for the first time, and select 'elephant', 'cat', and 'bird' (in that order), the value in the database will look like:
elephant||cat||bird
But: the next time I go to edit this resource, the "selected" items in the TV will not appear according to the order they are stored, but rather according to their position in the (alphabetized) master list. So they will show up in the form as:
So what happens is that when I save the resource (unless I go to the TV tab and manually re-sort the items before saving), the same 3 values are saved in the database, but the field value now looks like:
bird||cat||elephant
This may or may not be problematic depending on what you are trying to do. In my case, I was using a multi-select TV to select multiple content widgets that need to appear in a certain order, or css/js files that need to be loaded one-before-the-other, etc.
So: Is it realistic to expect that MODX should not change the way your data is stored in the database unless you explicitly change it in the editing form? If so, this is a bug that should be fixed.
Or, is the order of items in a multi-select list not something that one should expect to, or depend on, having control over? In that case, I have had an unreasonable expectation of this TV type and need to adjust my plans accordingly. And it isn't a bug, just a quirk that shouldn't hurt you unless you are abusing the TV type.
I'm suspecting the former: that this is a bug. I think the expectation "If I don't edit a particular TV, MODX shouldn't change the stored value when I save a resource" is a reasonable one.
What do you think?