From ef0b863c2bdd74d3acbdb89e47729ad1aaa75916 Mon Sep 17 00:00:00 2001 From: Michael Barrett <991592+mike182uk@users.noreply.github.com> Date: Tue, 16 May 2023 12:03:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20validation=20error=20whe?= =?UTF-8?q?n=20creating=200%=20offer=20(#16803)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Team/issues/3073 Fixed validation error when creating 0% offer. Issue was occurring due to a falsy check on the offer value. Have resolved by having a more strict check on the offer value based on the possible empty value it can be - If creating a new offer without providing an offer value, the value will be `undefined`. If supplying an offer value, then removing the offer value, the value will be an empty string. This check prevents `0` being classed as an invalid value. --- ghost/admin/app/validators/offer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ghost/admin/app/validators/offer.js b/ghost/admin/app/validators/offer.js index 02fe513e7d..2f2b33b48b 100644 --- a/ghost/admin/app/validators/offer.js +++ b/ghost/admin/app/validators/offer.js @@ -16,12 +16,8 @@ export default BaseValidator.create({ }, amount(model) { - if (!model.amount) { - if (model.type === 'trial') { - model.errors.add('amount', 'Free trial must be at least 1 day.'); - } else { - model.errors.add('amount', 'Please enter the amount.'); - } + if (model.amount === '' || model.amount === undefined) { + model.errors.add('amount', 'Please enter the amount.'); return this.invalidate(); }