show / hide password box

Added a selectbox to change the input box type from password to text.
This commit is contained in:
Daniel Steglich authored and Sunil Mohan Adapa committed 2015-08-22 13:03:00 +05:30
1 parent 286caf8917
commit d79437d2a2
2 files changed
+18 -1

No files matched your search

+4 -1
View File
@@ -87,7 +87,10 @@ class AddPPPoEForm(forms.Form):
available over this interfaces. Select Internal only for trusted networks.'),
choices=[('external', 'External'), ('internal', 'Internal')])
username = forms.CharField(label=_('Username'))
password = forms.CharField(label=_('Password'))
password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput())
showpw = forms.BooleanField(label=_('show password'),
required=False)
def __init__(self, *args, **kwargs):
"""Initialize the form, populate interface choices."""
@@ -58,6 +58,20 @@
}
});
$('#id_showpw').change(function() {
//changing type attribute from password to text is prevented by
//most browsers make a new form field works for me
if ($('#id_showpw').prop('checked')) {
$('#id_password').replaceWith(
$('#id_password').clone().attr(
'type', 'text'));
} else {
$('#id_password').replaceWith(
$('#id_password').clone().attr(
'type', 'password'));
}
});
})(jQuery);
</script>