Skip to content

Commit

Permalink
pkp/pkp-lib#10529 Fix: orderable FieldOptions doesn't show correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
NateWr committed Oct 18, 2024
1 parent 5b972e8 commit 2808a65
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/Form/fields/FieldOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@ export default {
: newVal;
},
},
mounted() {
/**
* Order selected options when isOrderable=true
*/
if (this.isOrderable && this.selectedValue?.length) {
this.localizedOptions = this.localizedOptions.sort((a, b) => {
let aIndex = this.selectedValue.findIndex(value => a.value === value);
let bIndex = this.selectedValue.findIndex(value => b.value === value);
aIndex = aIndex === -1 ? Number.MAX_SAFE_INTEGER : aIndex;
bIndex = bIndex === -1 ? Number.MAX_SAFE_INTEGER : bIndex;
return aIndex < bIndex ? -1 : 1;
})
}
},
methods: {
/**
* Move an option up in the list
Expand Down

0 comments on commit 2808a65

Please sign in to comment.