Skip to content

Commit

Permalink
added show password icon for login & register (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniyalfarman authored Feb 16, 2024
1 parent 6ce326e commit c356f02
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
9 changes: 9 additions & 0 deletions lms/static/js/student_account/views/LoginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
tpl: '#login-tpl',
events: {
'click .js-login': 'submitForm',
'click .toggle-password': 'togglePassword',
'click .forgot-password': 'forgotPassword',
'click .login-provider': 'thirdPartyAuth',
'click .enterprise-login': 'enterpriseSlugLogin',
Expand Down Expand Up @@ -147,6 +148,14 @@
this.toggleHelp(event, $help);
},

togglePassword: function(event) {
event.preventDefault();
var passwordField = document.querySelector("#login-password")
var newType = passwordField.getAttribute("type") === "password" ? "text" : "password"
passwordField.setAttribute("type", newType);
$(event.target).toggleClass("fa-eye fa-eye-slash");
},

enterpriseSlugLogin: function(event) {
event.preventDefault();
if (this.enterpriseSlugLoginURL) {
Expand Down
9 changes: 9 additions & 0 deletions lms/static/js/student_account/views/RegisterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
events: {
'click .js-register': 'submitForm',
'click .login-provider': 'thirdPartyAuth',
'click .toggle-password': 'togglePassword',
'click input[required][type="checkbox"]': 'liveValidateHandler',
'blur input[required], textarea[required], select[required]': 'liveValidateHandler',
'focus input[required], textarea[required], select[required]': 'handleRequiredInputFocus'
Expand Down Expand Up @@ -438,6 +439,14 @@
}
},

togglePassword: function(event) {
event.preventDefault();
var passwordField = document.querySelector("#register-password")
var newType = passwordField.getAttribute("type") === "password" ? "text" : "password"
passwordField.setAttribute("type", newType);
$(event.target).toggleClass("fa-eye fa-eye-slash");
},

saveSuccess: function() {
this.trigger('auth-complete');
},
Expand Down
12 changes: 12 additions & 0 deletions lms/static/sass/views/_login-register.scss
Original file line number Diff line number Diff line change
Expand Up @@ -932,3 +932,15 @@ body.open-modal {
overflow: hidden;
}

.wrapper-password {
position: relative;
}

.wrapper-password .toggle-password {
position: absolute;
top: 50%;
right: 10px;
transform: translateY(-50%);
z-index: 2;
margin-top: -3px;
}
41 changes: 23 additions & 18 deletions lms/templates/student_account/form_field.underscore
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,30 @@
</div>
<% } %>
<% } %>
<input id="<%- form %>-<%- name %>"
type="<%- type %>"
name="<%- name %>"
class="input-block <% if ( type === 'checkbox' ) { %>checkbox<% } %>"
<% if ( instructions ) { %>
aria-describedby="<%- form %>-<%- name %>-desc <%- form %>-<%- name %>-validation-error"
<div class="wrapper-<%- type %>">
<input id="<%- form %>-<%- name %>"
type="<%- type %>"
name="<%- name %>"
class="input-block <% if ( type === 'checkbox' ) { %>checkbox<% } %>"
<% if ( instructions ) { %>
aria-describedby="<%- form %>-<%- name %>-desc <%- form %>-<%- name %>-validation-error"
<% } %>
<% if ( restrictions.min_length ) { %> minlength="<%- restrictions.min_length %>"<% } %>
<% if ( restrictions.max_length ) { %> maxlength="<%- restrictions.max_length %>"<% } %>
<% if ( restrictions.readonly ) { %> readonly <% } %>
<% if ( required ) { %> required<% } %>
<% if ( typeof errorMessages !== 'undefined' ) {
_.each(errorMessages, function( msg, type ) {%>
data-errormsg-<%- type %>="<%- msg %>"
<% });
} %>
<% if ( placeholder ) { %> placeholder="<%- placeholder %>"<% } %>
value="<%- defaultValue %>"
/>
<% if ( type === 'password') { %>
<span toggle="#login-password" class="fa fa-fw fa-eye field-icon toggle-password"></span>
<% } %>
<% if ( restrictions.min_length ) { %> minlength="<%- restrictions.min_length %>"<% } %>
<% if ( restrictions.max_length && type !== 'password' ) { %> maxlength="<%- restrictions.max_length %>"<% } %>
<% if ( restrictions.readonly ) { %> readonly <% } %>
<% if ( required ) { %> required<% } %>
<% if ( typeof errorMessages !== 'undefined' ) {
_.each(errorMessages, function( msg, type ) {%>
data-errormsg-<%- type %>="<%- msg %>"
<% });
} %>
<% if ( placeholder ) { %> placeholder="<%- placeholder %>"<% } %>
value="<%- defaultValue %>"
/>
</div>
<% if ( type === 'checkbox' ) { %>
<label for="<%- form %>-<%- name %>">
<span class="label-text"><%= HtmlUtils.HTML(label) %></span>
Expand Down

0 comments on commit c356f02

Please sign in to comment.