From 79d8e64e9a57a49a6f0af77e9426024d2c8696bc Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 16 Sep 2022 13:34:36 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20tag=20slug=20not=20auto-?= =?UTF-8?q?matching=20tag=20title=20when=20creating=20new=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Ghost/commit/08b099e5274c3471724375924067381029b62220 - when the use of scratch values was removed a bug was introduced where only the first character of the tag title was used to set the slug when typing - bug was caused because previously we were checking against the original `tag.slug` value which wouldn't have been set yet because we were setting scratch values instead - updated the code to explicitly mark the slug value as being set manually if it's edited directly so the auto-update logic can use that to skip updates instead of comparing against old/unset values --- ghost/admin/app/components/tags/tag-form.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/components/tags/tag-form.js b/ghost/admin/app/components/tags/tag-form.js index bd2570ffb3..1c9e231377 100644 --- a/ghost/admin/app/components/tags/tag-form.js +++ b/ghost/admin/app/components/tags/tag-form.js @@ -117,10 +117,8 @@ export default class TagForm extends Component { newValue = newValue.trim(); } - tag[property] = newValue; - // Generate slug based on name for new tag when empty - if (property === 'name' && !tag.slug && tag.isNew) { + if (property === 'name' && tag.isNew && !this.hasChangedSlug) { let slugValue = slugify(newValue); if (/^#/.test(newValue)) { slugValue = 'hash-' + slugValue; @@ -128,6 +126,13 @@ export default class TagForm extends Component { tag.slug = slugValue; } + // ensure manual changes of slug don't get reset when changing name + if (property === 'slug') { + this.hasChangedSlug = !!newValue; + } + + tag[property] = newValue; + // clear validation message when typing tag.hasValidated.addObject(property); }