Class: CCS::Components::GovUK::Field::Input::PasswordInput

Inherits:
Object
  • Object
show all
Defined in:
lib/ccs/components/govuk/field/input/password_input.rb,
lib/ccs/components/govuk/field/input/password_input/show_hide_button.rb

Overview

GOV.UK Password input

This is used for generating the password input component from the GDS - Components - Password Input

Defined Under Namespace

Classes: ShowHideButton

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, context:, **options) ⇒ PasswordInput

Returns a new instance of PasswordInput.

Parameters:

  • field_type (Symbol, String)

    (:text) the input field type

  • value (String)

    the value if the input

  • prefix (Hash)

    optional prefix for the input field, see Fix#initialize for more details.

  • suffix (Hash)

    optional suffix for the input field, see Fix#initialize for more details.

  • input_wrapper (Hash)

    HTML options for the input wrapper

  • label (Hash)

    attributes for the label, see Label#initialize for more details.

  • before_input (String)

    text or HTML to go before the input

  • after_input (String)

    text or HTML to go after the input

  • attribute (String, Symbol)

    the attribute of the field

  • hint (Hash)

    attributes for the hint, see Hint#initialize for more details. If no hint is given then no hint will be rendered

  • form_group (Hash)

    attributes for the form group, see FormGroup#initialize for more details.

  • options (Hash)

    options that will be used for the parts of the field

Options Hash (**options):

  • :error_message (String) — default: nil

    the error message to be displayed

  • :model (ActiveModel) — default: nil

    optional model that can be used to find an error message

  • :form (ActionView::Helpers::FormBuilder) — default: nil

    optional form builder used to create the field and find the error message

  • :classes (String)

    additional CSS classes for the field HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ccs/components/govuk/field/input/password_input.rb', line 28

def initialize(attribute:, context:, **options)
  set_password_input_from_group_options(options)

  show_hide_button = ShowHideButton.new(attribute: attribute, context: context, after_input: options.delete(:after_input), **options)

  options[:attributes] ||= {}
  options[:attributes][:spellcheck] = false
  options[:attributes][:autocapitalize] = 'none'
  options[:attributes][:autocomplete] ||= 'current-password'

  @text_input = TextInput.new(
    context: context,
    attribute: attribute,
    after_input: show_hide_button.render,
    input_wrapper: {
      classes: 'govuk-password-input__wrapper'
    },
    classes: "govuk-password-input__input govuk-js-password-input-input #{options.delete(:classes)}".rstrip,
    field_type: :password,
    **options
  )
end