about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-08-12 12:11:15 +0200
committerGitHub <noreply@github.com>2020-08-12 12:11:15 +0200
commit7dc4c742650ac69ec9a4459b656e172283511e4c (patch)
tree43758243a2f4007e40a3c41b127bdf01a4a06b64 /app/javascript
parentd70c3ab4c39e642d41138ab693af77dd6c258e8c (diff)
Add client-side validation in password change forms (#14564)
* Fix client-side username validation at registration

It used the Account::USERNAME_RE regexp which is for *remote* users,
local user validation is stricter. Also take into account max username length.

* Add client-side form validation for password change

* Add client-side form validation to dedicated registration form

Previous changes only applied to the /about page, not the dedicated form on
/auth
Diffstat (limited to 'app/javascript')
-rw-r--r--app/javascript/packs/public.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js
index 777182b7f..551e281a8 100644
--- a/app/javascript/packs/public.js
+++ b/app/javascript/packs/public.js
@@ -126,6 +126,18 @@ function main() {
       }
     });
 
+    delegate(document, '#user_password,#user_password_confirmation', 'input', () => {
+      const password = document.getElementById('user_password');
+      const confirmation = document.getElementById('user_password_confirmation');
+      if (!confirmation) return;
+
+      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('');
+      }
+    });
+
     delegate(document, '.custom-emoji', 'mouseover', getEmojiAnimationHandler('data-original'));
     delegate(document, '.custom-emoji', 'mouseout', getEmojiAnimationHandler('data-static'));