show / hide password box

Added a selectbox to change the input box type from password to text.
This commit is contained in:
Daniel Steglich 2015-08-13 20:58:35 +02:00 committed by Sunil Mohan Adapa
parent 286caf8917
commit d79437d2a2
2 changed files with 18 additions and 1 deletions

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."""

View File

@ -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>