Skip to content

Instantly share code, notes, and snippets.

@sibsfinx
Last active December 20, 2015 01:49
Show Gist options
  • Save sibsfinx/6051975 to your computer and use it in GitHub Desktop.
Save sibsfinx/6051975 to your computer and use it in GitHub Desktop.
password field eye icon (simple_form + js)
# app/assets/javascripts/password-toggle.js.coffee
$ ->
$(".j-password-toggle").on "click", ->
icon = $(this).find("[class*='icon']")
icon.toggleClass('fontello-icon-eye')
icon.toggleClass('fontello-icon-eye-off')
input = $(this).closest('form').find('.j-password-input')
type = input.attr("type")
if type is "text"
input.attr "type", "password"
else
input.attr "type", "text"
# app/inputs/password_input.rb
class PasswordInput < SimpleForm::Inputs::Base
include IconHelper
enable :placeholder, :maxlength
def input
input_html_options[:class] << " j-password-input "
template.content_tag :div, :class => 'input-append user-select-none' do
@builder.password_field(attribute_name, input_html_options) +
template.content_tag(:span, template.fontello('eye-off'), class: 'add-on j-password-toggle')
end
end
end
// app/assets/stylesheets/utils.sass
.user-select-none
+user-select(none)
// bootstrap-sass mixin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment