From 5dc23f137aa39aee84e4435a1de66963fae0b36f Mon Sep 17 00:00:00 2001 From: Blesilda Ramirez Date: Fri, 25 Oct 2024 02:29:47 +0800 Subject: [PATCH] pkp/pkp-lib#10529 Fix: orderable FieldOptions doesn't show correct --- 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 6f9d51bcf..d49d56ef4 100644 --- a/src/components/Form/fields/FieldOptions.vue +++ b/src/components/Form/fields/FieldOptions.vue @@ -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