Skip to content

Commit

Permalink
pkp/pkp-lib#10529 Fix: orderable FieldOptions doesn't show correct
Browse files Browse the repository at this point in the history
  • Loading branch information
blesildaramirez committed Oct 24, 2024
1 parent b380654 commit 5dc23f1
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 @@ -172,6 +172,20 @@ export default {
return classes;
},
},
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 5dc23f1

Please sign in to comment.