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

#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
25
# 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 "
  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
    @builder.password_field(attribute_name, merged_input_options) +
    password_uncloaking_div +
    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
  else
    @builder.password_field(attribute_name, merged_input_options)
  end
end

#linked_field_nameObject



35
36
37
# File 'lib/simple_form_password_with_hints/password_with_sync_input.rb', line 35

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

#password_uncloaking_divObject



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

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