Class: PasswordWithSyncInput

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

Instance Method Summary collapse

Instance Method Details

#controlsObject



26
27
28
29
30
31
32
33
34
# File 'lib/simple_form_password_with_hints/password_with_sync_input.rb', line 26

def controls
  template.(:div, '', class: 'sfpwh-controls js-sfpwh-controls') do
    template.(
      :span,
      t('simple_form_password_with_hints.test_fields_matching'),
      class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--match js-sfpwh-hint-match'
      )
  end
end

#input(wrapper_options = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_form_password_with_hints/password_with_sync_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-sync-input "
  input_wrapper_class = 'sfpwh-input-div'
  input_wrapper_class += ' sfpwh-input-div-invalid' if has_errors?
  if options[:compare_with_field]
    if merged_input_options[:data].nil?
      merged_input_options[:data] = { link_to: linked_field_name }
    else
      merged_input_options[:data][:link_to] = linked_field_name
    end
    ( template.(:div, '', class: input_wrapper_class) do
      [
        @builder.password_field(attribute_name, merged_input_options) +
        password_uncloaking_div
      ].compact.join.html_safe
    end ) + controls
  else
    @builder.password_field(attribute_name, merged_input_options)
  end
end

#linked_field_nameObject



44
45
46
# File 'lib/simple_form_password_with_hints/password_with_sync_input.rb', line 44

def linked_field_name
  "#{@builder.object_name}[#{options[:compare_with_field]}]"
end

#password_uncloaking_divObject



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

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