From 303c79be1f9a4ef46329d2cdfd4640cac8159cf3 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 14 Apr 2020 16:06:02 +1000 Subject: [PATCH] Only clear mapped properties if the field id remains the same --- .../components/wizard-custom-field.js.es6 | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 3c54748a..70ff06ab 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -19,11 +19,21 @@ export default Component.extend({ showMinLength: or('isText', 'isTextarea', 'isUrl', 'isComposer'), categoryPropertyTypes: selectKitContent(['id', 'slug']), - @observes('field.type') - clearMapped() { - schema.field.mapped.forEach(property => { - this.set(`field.${property}`, null); - }); + // clearMapped only clears mapped fields if the field type of a specific field + // changes, and not when switching between fields. Switching between fields also + // changes the field.type property in this component + + @observes('field.id', 'field.type') + clearMapped(ctx, changed) { + if (this.field.id === this.bufferedFieldId) { + schema.field.mapped.forEach(property => { + this.set(`field.${property}`, null); + }); + } + + if (changed === 'field.type') { + this.set('bufferedFieldId', this.field.id); + } }, setupTypeOutput(fieldType, options) {