From b74a46a89fca7bb3344f2da3e48e91f5bd712b7c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Apr 2020 07:21:44 +1000 Subject: [PATCH] Fix: new items may not have type on creation --- .../discourse/lib/wizard-schema.js.es6 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 07ac1ad5..1699c3f5 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -197,7 +197,6 @@ if (Discourse.SiteSettings.wizard_apis_enabled) { export function setWizardDefaults(obj, itemType, opts={}) { const objSchema = wizardSchema[itemType]; const basicDefaults = objSchema.basic; - const typeDefaults = objSchema.types[obj.type]; Object.keys(basicDefaults).forEach(property => { let defaultValue = get(basicDefaults, property); @@ -206,12 +205,16 @@ export function setWizardDefaults(obj, itemType, opts={}) { } }); - if (typeDefaults) { - Object.keys(typeDefaults).forEach(property => { - if (typeDefaults.hasOwnProperty(property)) { - set(obj, property, get(typeDefaults, property)); - } - }); + if (objSchema.types) { + const typeDefaults = objSchema.types[obj.type]; + + if (typeDefaults) { + Object.keys(typeDefaults).forEach(property => { + if (typeDefaults.hasOwnProperty(property)) { + set(obj, property, get(typeDefaults, property)); + } + }); + } } return obj;