Class: Koi::Form::Elements::Document

Inherits:
GOVUKDesignSystemFormBuilder::Base
  • Object
show all
Includes:
FileElement
Defined in:
lib/koi/form/elements/document.rb

Instance Method Summary collapse

Methods included from FileElement

#html

Constructor Details

#initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, mime_types:, **kwargs) ⇒ Document

Returns a new instance of Document.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/koi/form/elements/document.rb', line 11

def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, mime_types:,
               **kwargs, &)
  super(builder, object_name, attribute_name, &)

  @mime_types      = mime_types
  @label           = label
  @caption         = caption
  @hint            = hint
  @html_attributes = kwargs.merge(file_input_options)
  @form_group      = form_group
end

Instance Method Details

#previewObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/koi/form/elements/document.rb', line 23

def preview
  options = {}
  add_option(options, :data, "#{stimulus_controller}_target", "preview")
  add_option(options, :class, "preview-file")
  add_option(options, :class, "hidden") unless preview?

  tag.div(**options) do
    filename = @builder.object.send(@attribute_name).filename.to_s
    tag.p(filename, class: "preview-filename") + destroy_element_trigger
  end
end