From 6f0ce6782dcb22229b57d93e1b3889109f8c400d Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Thu, 24 Oct 2024 13:01:50 +0100 Subject: [PATCH] pkp/pkp-lib#10529 Fix: orderable FieldOptions doesn't show correct order (#429) --- src/components/Form/fields/FieldOptions.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/Form/fields/FieldOptions.vue b/src/components/Form/fields/FieldOptions.vue index a944b42c2..33b87c56d 100644 --- a/src/components/Form/fields/FieldOptions.vue +++ b/src/components/Form/fields/FieldOptions.vue @@ -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