From b6ef0af8948aee4e39ed786db511ce9dfb409df5 Mon Sep 17 00:00:00 2001 From: Artem Tiumentcev Date: Sun, 11 Sep 2016 20:37:53 +0300 Subject: [PATCH] Fix js validation of the password in dynamic UI Before this patch clicking on an eye icon disabled javascript validation of the password. I added to password field the attribute 'data-type=password' and in js changed the selector to include new attribute in the selector, that attaches the check function. Change-Id: Ic7e57814a68c315e570c120f31febdada73079a7 Closes-Bug: #1567859 (cherry picked from commit d50cb35ece120b97a0c309d84dd2708c8c35c3ab) --- muranodashboard/dynamic_ui/fields.py | 7 +++++-- muranodashboard/static/muranodashboard/js/passwordfield.js | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/muranodashboard/dynamic_ui/fields.py b/muranodashboard/dynamic_ui/fields.py index b7de62770..1f561e5ed 100644 --- a/muranodashboard/dynamic_ui/fields.py +++ b/muranodashboard/dynamic_ui/fields.py @@ -214,6 +214,7 @@ class PasswordField(CharField): % special_characters) has_clone = False original = True + attrs = {'data-type': 'password'} validate_password = django_validator.RegexValidator( password_re, _('The password must contain at least one letter, one \ number and one special character'), 'invalid') @@ -239,7 +240,8 @@ class PasswordField(CharField): kwargs.update({'label': label, 'error_messages': kwargs.get('error_messages', {}), - 'widget': forms.PasswordInput(render_value=True)}) + 'widget': forms.PasswordInput(attrs=self.attrs, + render_value=True)}) validators = kwargs.get('validators') help_text = kwargs.get('help_text') @@ -256,7 +258,8 @@ class PasswordField(CharField): 'invalid', self.validate_password.message) kwargs['min_length'] = kwargs.get('min_length', 7) kwargs['max_length'] = kwargs.get('max_length', 255) - kwargs['widget'] = self.PasswordInput(render_value=True) + kwargs['widget'] = self.PasswordInput(attrs=self.attrs, + render_value=True) else: if not help_text: # NOTE(kzaitsev) There are custom validators for password, diff --git a/muranodashboard/static/muranodashboard/js/passwordfield.js b/muranodashboard/static/muranodashboard/js/passwordfield.js index b3845fd21..2f7129ce6 100644 --- a/muranodashboard/static/muranodashboard/js/passwordfield.js +++ b/muranodashboard/static/muranodashboard/js/passwordfield.js @@ -81,6 +81,7 @@ $(function() { mainCheck(div, meetRequirements, true, text); } - $("input[type='password']").not("[id$='-clone']").keyup(checkStrengthRemoveErrIfMatches); - $("input[id$='-clone'][type='password']").keyup(checkPasswordsMatch); + $(document).on("keyup", "input[data-type='password']:not([id$='clone'])", + checkStrengthRemoveErrIfMatches); + $(document).on("keyup", "input[id$='-clone'][data-type='password']", checkPasswordsMatch); });