Skip to content

Commit

Permalink
Add button to show and hide password in the devise registrations form
Browse files Browse the repository at this point in the history
Makes it easy for a user to check that he have typed the password correctly.
  • Loading branch information
linuxonrails authored and hennevogel committed Apr 19, 2023
1 parent fd01351 commit e61c853
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//= require osem-bootstrap
//= require osem-revisionhistory
//= require osem-commercials
//= require osem-register
//= require unobtrusive_flash
//= require unobtrusive_flash_bootstrap
//= require countable
Expand Down
15 changes: 15 additions & 0 deletions app/assets/javascripts/osem-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$( document ).ready(function() {

$('.osem-register button.show-or-hide-password').click(function() {
const is_locked = $(this).data('lock');
$(this).data('lock', !is_locked);
$(this).parents('.osem-register').find('input').attr('type', is_locked ? 'text' : 'password');
if (is_locked) {
$(this).find('.show-password').hide();
$(this).find('.hide-password').show();
} else {
$(this).find('.show-password').show();
$(this).find('.hide-password').hide();
}
} );
} );
6 changes: 4 additions & 2 deletions app/views/devise/registrations/_form_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
= f.label :password, 'Password'
- if [email protected]?
%abbr{title: 'This field is required'} *
= f.password_field :password, required: [email protected]?, class: 'form-control', placeholder: 'Password'
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: [email protected]?, placeholder: 'Password', method: :password }

.form-group
= f.label :password_confirmation, 'Password Confirmation'
= f.password_field :password_confirmation, required: [email protected]?, class: 'form-control', placeholder: 'Password Confirmation'
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: [email protected]?, placeholder: 'Password Confirmation', method: :password_confirmation }

- if @user.persisted?
%p.text-muted
Leave blank if you don't want to change your password
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.input-group.osem-register
= f.password_field method, required: required, class: 'form-control', placeholder: placeholder
.input-group-btn
%button.btn.btn-default{ type: 'button', class: 'show-or-hide-password', 'data-lock': "true" }
%span.show-password
%i.fa-solid.fa-lock
Show password
%span.hide-password{ style: 'display: none'}
%i.fa-solid.fa-unlock
Hide password

0 comments on commit e61c853

Please sign in to comment.