What happened?
Description
When using a multi-select field (https://craftcms.com/docs/5.x/reference/field-types/multi-select.html) the back-end system adheres to the order the items are listed on the options within the field. If you pick these out of order, upon save they get re-sorted into the correct order.
However, on the front-end when looping the field and the selected options, the order is presented in the order that the editor picked them.
Would it be possible to ensure that the order matches the back-end and is ordered by the native order of the list options.
I am not sure if this is a bug, but I believe this was working correctly when I first set up these fields and tested them.
I can see arguments for both cases, so perhaps a flag or option we can pass into our twig templates to order by the field options rather than the picked options. Even then though, he CMS shows them in the order of the field options, so it might be best to stick to this regardless. I can't really see a reason not to stick to ordering by the values order.



{% dd(entry.getRootOwner().ratedCurrentOptions) %}
{% for option in entry.getRootOwner().ratedCurrentOptions %}
{{ option.label }}{{ not loop.last ? ', ' }}
{% endfor %}
We can get around this via some filters like so:
{% for option in entry.getRootOwner().ratedCurrentOptions.options|filter(option => option.selected) %}
{{ option.label }}{{ not loop.last ? ', ' }}
{% endfor %}
But this seems like an additional step to take to match the back-end and front-end.
Steps to reproduce
- Create a mult-select field with options
- Pick the options out of order
- When saving the entry in the back-end the selected options are re-ordered by the original order of the fields options
- Looping through the field in twig and the order is output as per the 'selected' order not the filed options order.
Expected behavior
The default loop order should match the back-end system view and adhere to the order of the field options.
Actual behavior
The order is shown as the order 'picked' by the author and not the field options order, which also mi-matches what is shown on the back-end.
Craft CMS version
Craft Pro 5.4.6
PHP version
8.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
What happened?
Description
When using a multi-select field (https://craftcms.com/docs/5.x/reference/field-types/multi-select.html) the back-end system adheres to the order the items are listed on the options within the field. If you pick these out of order, upon save they get re-sorted into the correct order.
However, on the front-end when looping the field and the selected options, the order is presented in the order that the editor picked them.
Would it be possible to ensure that the order matches the back-end and is ordered by the native order of the list options.
I am not sure if this is a bug, but I believe this was working correctly when I first set up these fields and tested them.
I can see arguments for both cases, so perhaps a flag or option we can pass into our twig templates to order by the field options rather than the picked options. Even then though, he CMS shows them in the order of the field options, so it might be best to stick to this regardless. I can't really see a reason not to stick to ordering by the values order.
We can get around this via some filters like so:
But this seems like an additional step to take to match the back-end and front-end.
Steps to reproduce
Expected behavior
The default loop order should match the back-end system view and adhere to the order of the field options.
Actual behavior
The order is shown as the order 'picked' by the author and not the field options order, which also mi-matches what is shown on the back-end.
Craft CMS version
Craft Pro 5.4.6
PHP version
8.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions