From b4528b9e27ef27c837c5078ef4dc281ecd91626e Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Mon, 6 Mar 2023 17:39:59 -0700 Subject: [PATCH] FIX: Trim whitespace on email field for invites (#20547) If the whitespace isn't trimmed from the input field the email is considered invalid, and the button remains greyed out. We should handle removing any trailing whitespace and not rely on the user trying to see it themselves. --- .../discourse/app/controllers/create-invite.js | 8 ++++---- .../tests/acceptance/create-invite-modal-test.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/create-invite.js b/app/assets/javascripts/discourse/app/controllers/create-invite.js index 3f8dbf832ed..35f25166176 100644 --- a/app/assets/javascripts/discourse/app/controllers/create-invite.js +++ b/app/assets/javascripts/discourse/app/controllers/create-invite.js @@ -34,12 +34,12 @@ export default Controller.extend( @discourseComputed("buffered.emailOrDomain") isEmail(emailOrDomain) { - return emailValid(emailOrDomain); + return emailValid(emailOrDomain?.trim()); }, @discourseComputed("buffered.emailOrDomain") isDomain(emailOrDomain) { - return hostnameValid(emailOrDomain); + return hostnameValid(emailOrDomain?.trim()); }, isLink: not("isEmail"), @@ -83,9 +83,9 @@ export default Controller.extend( if (data.emailOrDomain) { if (emailValid(data.emailOrDomain)) { - data.email = data.emailOrDomain; + data.email = data.emailOrDomain?.trim(); } else if (hostnameValid(data.emailOrDomain)) { - data.domain = data.emailOrDomain; + data.domain = data.emailOrDomain?.trim(); } delete data.emailOrDomain; } diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js index ce818cb6fcd..0858762c635 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js @@ -155,7 +155,7 @@ acceptance("Invites - Email Invites", function (needs) { "sends skip_email to server" ); - await fillIn("#invite-email", "test2@example.com"); + await fillIn("#invite-email", "test2@example.com "); assert.ok(exists(".send-invite"), "shows save and send email button"); await click(".send-invite"); assert.ok(