about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRens Groothuijsen <l.groothuijsen@alumni.maastrichtuniversity.nl>2021-12-05 21:49:50 +0100
committerGitHub <noreply@github.com>2021-12-05 21:49:50 +0100
commit66baa629ea1c3890d5c631099d41e6af14974d7e (patch)
tree3b1a25b5b430dbfce72143b2f5a0d3acca8a165b
parent0fb9536d3888cd7b6013c239d5be85f095a6e8ad (diff)
Show correct error message if chosen password is too long (#17082)
* Add correct error message for exceeding max length on password confirmation field

* Code style fixes
-rw-r--r--app/javascript/packs/public.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js
index 8c5c15b8f..c0c088646 100644
--- a/app/javascript/packs/public.js
+++ b/app/javascript/packs/public.js
@@ -120,7 +120,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('');
@@ -132,7 +134,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('');