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

#controlsObject



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

def controls
  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

#input(wrapper_options = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# 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 "
  input_wrapper_class = 'sfpwh-input-div'
  input_wrapper_class += ' sfpwh-input-div-invalid' if has_errors?
  ( template.(:div, '', class: input_wrapper_class) do
    [
      @builder.password_field(attribute_name, merged_input_options),
      password_uncloaking_div
    ].compact.join.html_safe
  end ) + controls
end

#length_divObject



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

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



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

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



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

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



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

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

#special_char_divObject



70
71
72
73
74
75
76
77
# File 'lib/simple_form_password_with_hints/password_with_hints_input.rb', line 70

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



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

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