From 0412decaec7264ff6c069ef5e28f78d0577f3393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20der=20Winden?= Date: Mon, 12 Aug 2024 11:35:21 +0200 Subject: [PATCH] Excerpt form error fix (#20730) fixes https://linear.app/tryghost/issue/DES-435/excerpt-in-post-settings-has-an-inconsistent-error-state The excerpt form field seemed to not be properly handling errors. However, it was a case of the error styling being overruled by the regular styling, causing the red border to only show upon `:focus` when there is an error in the excerpt. I've rewritten the logic to be slightly less obfuscated and added some CSS to circumvent the issue. --- ghost/admin/app/styles/patterns/forms.css | 2 +- ghost/admin/app/validators/post.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ghost/admin/app/styles/patterns/forms.css b/ghost/admin/app/styles/patterns/forms.css index 4eba90853a..bf0a74b085 100644 --- a/ghost/admin/app/styles/patterns/forms.css +++ b/ghost/admin/app/styles/patterns/forms.css @@ -225,7 +225,7 @@ select { .gh-select.error, .error .gh-input-append, select.error { - border-color: var(--red); + border-color: var(--red)!important; } .gh-input:focus, diff --git a/ghost/admin/app/validators/post.js b/ghost/admin/app/validators/post.js index f157e4d2f6..24da716349 100644 --- a/ghost/admin/app/validators/post.js +++ b/ghost/admin/app/validators/post.js @@ -62,12 +62,11 @@ export default BaseValidator.create({ customExcerpt(model) { if (!validator.isLength(model.customExcerpt || '', 0, 300)) { - if (model.feature.editorExcerpt) { - model.errors.add('customExcerpt', 'Excerpt cannot be longer than 300 characters.'); - } else { - model.errors.add('customExcerpt', 'Excerpt cannot be longer than 300 characters.'); - } + const errorMessage = 'Excerpt cannot be longer than 300 characters.'; + model.errors.add('customExcerpt', errorMessage); this.invalidate(); + } else { + model.errors.remove('customExcerpt'); } },