Skip to content

Commit e61c853

Browse files
linuxonrailshennevogel
authored andcommitted
Add button to show and hide password in the devise registrations form
Makes it easy for a user to check that he have typed the password correctly.
1 parent fd01351 commit e61c853

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

app/assets/javascripts/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
//= require osem-bootstrap
4242
//= require osem-revisionhistory
4343
//= require osem-commercials
44+
//= require osem-register
4445
//= require unobtrusive_flash
4546
//= require unobtrusive_flash_bootstrap
4647
//= require countable
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$( document ).ready(function() {
2+
3+
$('.osem-register button.show-or-hide-password').click(function() {
4+
const is_locked = $(this).data('lock');
5+
$(this).data('lock', !is_locked);
6+
$(this).parents('.osem-register').find('input').attr('type', is_locked ? 'text' : 'password');
7+
if (is_locked) {
8+
$(this).find('.show-password').hide();
9+
$(this).find('.hide-password').show();
10+
} else {
11+
$(this).find('.show-password').show();
12+
$(this).find('.hide-password').hide();
13+
}
14+
} );
15+
} );

app/views/devise/registrations/_form_fields.html.haml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
= f.label :password, 'Password'
1919
2020
%abbr{title: 'This field is required'} *
21-
= f.password_field :password, required: [email protected]?, class: 'form-control', placeholder: 'Password'
21+
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: [email protected]?, placeholder: 'Password', method: :password }
22+
2223
.form-group
2324
= f.label :password_confirmation, 'Password Confirmation'
24-
= f.password_field :password_confirmation, required: [email protected]?, class: 'form-control', placeholder: 'Password Confirmation'
25+
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: [email protected]?, placeholder: 'Password Confirmation', method: :password_confirmation }
26+
2527
- if @user.persisted?
2628
%p.text-muted
2729
Leave blank if you don't want to change your password
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.input-group.osem-register
2+
= f.password_field method, required: required, class: 'form-control', placeholder: placeholder
3+
.input-group-btn
4+
%button.btn.btn-default{ type: 'button', class: 'show-or-hide-password', 'data-lock': "true" }
5+
%span.show-password
6+
%i.fa-solid.fa-lock
7+
Show password
8+
%span.hide-password{ style: 'display: none'}
9+
%i.fa-solid.fa-unlock
10+
Hide password

0 commit comments

Comments
 (0)