-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
fd01351
commit e61c853
Showing
4 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
10 changes: 10 additions & 0 deletions
10
app/views/devise/registrations/_password_field_with_view_password_button.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |