networks: Fix showing password during PPPoE edit

- Javascript was missing for the template altogether.  Added one similar
  to create case.

- Minor refactoring to existing javascript.

- Consistent styling for display label and field id.
This commit is contained in:
Sunil Mohan Adapa 2015-08-22 20:22:08 +05:30
parent 1e10fb76fc
commit 4f75f44769
3 changed files with 22 additions and 14 deletions

View File

@ -89,8 +89,8 @@ available over this interfaces. Select Internal only for trusted networks.'),
username = forms.CharField(label=_('Username')) username = forms.CharField(label=_('Username'))
password = forms.CharField(label=_('Password'), password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput()) widget=forms.PasswordInput())
showpw = forms.BooleanField(label=_('show password'), show_password = forms.BooleanField(label=_('Show password'),
required=False) required=False)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Initialize the form, populate interface choices.""" """Initialize the form, populate interface choices."""

View File

@ -58,18 +58,15 @@
} }
}); });
$('#id_showpw').change(function() { $('#id_show_password').change(function() {
//changing type attribute from password to text is prevented by // Changing type attribute from password to text is prevented by
//most browsers make a new form field works for me // most browsers. Making a new form field works.
if ($('#id_showpw').prop('checked')) { new_type = 'password';
$('#id_password').replaceWith( if ($('#id_show_password').prop('checked'))
$('#id_password').clone().attr( new_type = 'text';
'type', 'text'));
} else { $('#id_password').replaceWith(
$('#id_password').replaceWith( $('#id_password').clone().attr('type', new_type));
$('#id_password').clone().attr(
'type', 'password'));
}
}); });
})(jQuery); })(jQuery);

View File

@ -58,6 +58,17 @@
} }
}); });
$('#id_show_password').change(function() {
// Changing type attribute from password to text is prevented by
// most browsers. Making a new form field works.
new_type = 'password';
if ($('#id_show_password').prop('checked'))
new_type = 'text';
$('#id_password').replaceWith(
$('#id_password').clone().attr('type', new_type));
});
})(jQuery); })(jQuery);
</script> </script>