From 3066c223671d79ab6d8d44f95148aefbf063ba81 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 15 Apr 2020 13:21:40 +1000 Subject: [PATCH] bugfix --- .../components/wizard-field-category.js.es6 | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/assets/javascripts/wizard/components/wizard-field-category.js.es6 b/assets/javascripts/wizard/components/wizard-field-category.js.es6 index 32f1a1e2..dd82c909 100644 --- a/assets/javascripts/wizard/components/wizard-field-category.js.es6 +++ b/assets/javascripts/wizard/components/wizard-field-category.js.es6 @@ -3,27 +3,30 @@ import Category from 'discourse/models/category'; export default Ember.Component.extend({ didInsertElement() { - const value = this.get('field.value'); + const property = this.field.property || 'id'; + const value = this.field.value; + if (value) { - const property = this.get('field.property') || 'id'; - const categories = [...value].map(v => { - return property === 'id' ? - Category.findById(v) : - Category.findBySlug(v); - }); - this.set('categories', categories); + this.set('categories', [...value].reduce((result, v) => { + let val = property === 'id' ? Category.findById(v) : Category.findBySlug(v); + if (val) result.push(val); + return result; + }, [])); } }, - + @observes('categories') setValue() { - const categories = this.get('categories'); - if (categories.length) { - const property = this.get('field.property') || 'id'; - let value = categories.length === 1 ? - categories[0][property] : - categories.map(c => c[property]); - this.set('field.value', value); + const categories = (this.categories || []).filter(c => !!c); + const property = this.field.property || 'id'; + + if (categories.length) { + this.set('field.value', categories.reduce((result, c) => { + if (c && c[property]) { + result.push(c[property]) + } + return result; + }, [])); } } }); \ No newline at end of file