Originally posted by **mnordhaus** November 24, 2023
Hi Community,
I wrote an change event listender so that it calculates the weights for the navigation based on the sort order:
```JavaScript
window.CMS.registerEventListener({
name: 'change',
collection: 'config',
field: 'main',
handler: ({ data, collection, field }) => {
n = 1;
let currentValue = [...data.main];
currentValue.forEach(mainItem => {
mainItem.weight = n++;
});
return {...data, main: currentValue };
},
});
```
And this is the related collection config:
```yaml
- name: config
label: 'Website Configuration'
files:
- name: navigation
file: config/_default/menus.yaml
label: 'Navigation'
fields:
- name: main
label: Main Navigation
label_singular: Main Navigation Item
widget: list
collapsed: true
fields:
- name: name
label: 'Name'
hint: 'Name of the navigation item that gets displayed to the user'
widget: string
- name: url
label: 'Url'
hint: 'Absolute (e.g. https://exemple.com/page.html) or relative (e.g. ../page.html) url or anchor link (like /#contact or ./#contact).'
widget: string
- name: weight
label: Weight
hint: 'The Navigation is sorted by this number'
```
While it is by design that the collection is initially, collapsed the modification of the data causes that the list will be collapse after I have opened it and made modification. The code itself does what it should and adjusts the weights perfectly fine.
But my expected behavior is that the list keeps uncollapsed after the change.
Any ideas what could be wrong with my code?
Best,
Markus
Discussed in https://github.com/StaticJsCMS/static-cms/discussions/997