From 59a5193280237777e7dcfc39664b534c92eac30a Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Sun, 5 Dec 2021 21:49:50 +0100 Subject: [PATCH] [Glitch] Show correct error message if chosen password is too long Port 66baa629ea1c3890d5c631099d41e6af14974d7e to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/packs/public.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/javascript/flavours/glitch/packs/public.js b/app/javascript/flavours/glitch/packs/public.js index dccdbc8d0..a92f3d5a8 100644 --- a/app/javascript/flavours/glitch/packs/public.js +++ b/app/javascript/flavours/glitch/packs/public.js @@ -99,7 +99,9 @@ function main() { delegate(document, '#registration_user_password_confirmation,#registration_user_password', 'input', () => { const password = document.getElementById('registration_user_password'); const confirmation = document.getElementById('registration_user_password_confirmation'); - if (password.value && password.value !== confirmation.value) { + if (confirmation.value && confirmation.value.length > password.maxLength) { + confirmation.setCustomValidity((new IntlMessageFormat(messages['password_confirmation.exceeds_maxlength'] || 'Password confirmation exceeds the maximum password length', locale)).format()); + } else if (password.value && password.value !== confirmation.value) { confirmation.setCustomValidity((new IntlMessageFormat(messages['password_confirmation.mismatching'] || 'Password confirmation does not match', locale)).format()); } else { confirmation.setCustomValidity(''); @@ -111,7 +113,9 @@ function main() { const confirmation = document.getElementById('user_password_confirmation'); if (!confirmation) return; - if (password.value && password.value !== confirmation.value) { + if (confirmation.value && confirmation.value.length > password.maxLength) { + confirmation.setCustomValidity((new IntlMessageFormat(messages['password_confirmation.exceeds_maxlength'] || 'Password confirmation exceeds the maximum password length', locale)).format()); + } else if (password.value && password.value !== confirmation.value) { confirmation.setCustomValidity((new IntlMessageFormat(messages['password_confirmation.mismatching'] || 'Password confirmation does not match', locale)).format()); } else { confirmation.setCustomValidity('');