Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to show and hide password in the devise registrations form #3117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 !@user.persisted?
%abbr{title: 'This field is required'} *
= f.password_field :password, required: !@user.persisted?, class: 'form-control', placeholder: 'Password'
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: !@user.persisted?, placeholder: 'Password', method: :password }

.form-group
= f.label :password_confirmation, 'Password Confirmation'
= f.password_field :password_confirmation, required: !@user.persisted?, class: 'form-control', placeholder: 'Password Confirmation'
= render partial: 'devise/registrations/password_field_with_view_password_button', locals: { f: f, required: !@user.persisted?, 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