Skip to content

Commit

Permalink
pkp/pkp-lib#10529 Fix: orderable FieldOptions doesn't show correct or…
Browse files Browse the repository at this point in the history
…der (#429)
  • Loading branch information
NateWr authored Oct 24, 2024
1 parent 006c931 commit 6f0ce67
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 6f0ce67

Please sign in to comment.