Class: PasswordWithHintsInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Defined in:
lib/simple_form_password_with_hints/password_with_hints_input.rb

Instance Method Summary collapse

Instance Method Details

#input(wrapper_options = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 4

def input(wrapper_options = nil)
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
  merged_input_options[:class] << " js-sfpwh-input js-sfpwh-hints-input "
  @builder.password_field(attribute_name, merged_input_options) +
    password_uncloaking_div +
    template.(:div, '', class: 'sfpwh-controls js-sfpwh-controls') do
      [
        length_div,
        uppercase_div,
        lowercase_div,
        numeric_div,
        special_char_div,
      ].compact.join.html_safe
    end
end

#length_divObject



28
29
30
31
32
33
34
35
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 28

def length_div
  template.(
    :span,
    t('simple_form_password_with_hints.test_chars', min_length: options[:validators][:length]),
    data: { length: options[:validators][:length] },
    class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--length js-sfpwh-hint-length'
  ) if should_display?(:length)
end

#lowercase_divObject



45
46
47
48
49
50
51
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 45

def lowercase_div
  template.(
    :span,
    t('simple_form_password_with_hints.test_lowercase'),
    class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--lowercase js-sfpwh-hint-lowercase'
  ) if should_display?(:lowercase_char)
end

#numeric_divObject



53
54
55
56
57
58
59
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 53

def numeric_div
  template.(
    :span,
    t('simple_form_password_with_hints.test_numeric'),
    class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--number js-sfpwh-hint-number'
  ) if should_display?(:numeric_char)
end

#password_uncloaking_divObject



20
21
22
23
24
25
26
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 20

def password_uncloaking_div
  template.(
    :span,
    '',
    class: 'sfpwh-password-toggle js-sfpwh-password-toggle'
  ) if options[:allow_password_uncloaking]
end

#special_char_divObject



61
62
63
64
65
66
67
68
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 61

def special_char_div
  template.(
    :span,
    t('simple_form_password_with_hints.test_special_char'),
    data: { chars: options[:validators][:special_char] },
    class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--special js-sfpwh-hint-special'
  ) if should_display?(:special_char)
end

#uppercase_divObject



37
38
39
40
41
42
43
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 37

def uppercase_div
  template.(
    :span,
    t('simple_form_password_with_hints.test_uppercase'),
    class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--uppercase js-sfpwh-hint-uppercase'
  ) if should_display?(:uppercase_char)
end