Last active
December 20, 2015 01:49
-
-
Save sibsfinx/6051975 to your computer and use it in GitHub Desktop.
password field eye icon (simple_form + js)
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
# 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" |
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
# 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 |
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
// 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