]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Add client-side validation in password change forms
authorThibG <thib@sitedethib.com>
Wed, 12 Aug 2020 10:11:15 +0000 (12:11 +0200)
committerThibaut Girka <thib@sitedethib.com>
Thu, 13 Aug 2020 20:26:22 +0000 (22:26 +0200)
Port 7dc4c742650ac69ec9a4459b656e172283511e4c to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/packs/public.js

index 8168e87da9d7664ad7e207ce09796d05da5a5fbb..b9b588dc6b4930a64df18958bdb99ed6d5121b7f 100644 (file)
@@ -105,6 +105,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'));