Class: Forms::FileInput

Inherits:
Phlex::HTML
  • Object
show all
Includes:
PhlexForms::DelegatedField
Defined in:
lib/forms/file_input.rb

Overview

A model-bound <input type="file">, delegating to DaisyUI::FileInput.

Direct Known Subclasses

Plain::FileInput

Constant Summary

Constants included from PhlexForms::DelegatedField

PhlexForms::DelegatedField::IGNORED_MODIFIERS

Instance Method Summary collapse

Constructor Details

#initialize(*modifiers, name: nil, id: nil, multiple: false, accept: nil, error: false, disabled: false, required: false, full_width: true, **attributes) ⇒ FileInput

Returns a new instance of FileInput.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/forms/file_input.rb', line 8

def initialize(*modifiers, name: nil, id: nil, multiple: false, accept: nil,
               error: false, disabled: false, required: false, full_width: true, **attributes)
  @modifiers = normalize_modifiers(modifiers)
  # Rails file_field parity: a multiple input needs an array param name, or
  # the browser collapses the selection into one scalar file — which a host
  # app's `params.expect(attr: [])` then silently discards.
  @name = multiple && name && !name.to_s.end_with?("[]") ? "#{name}[]" : name
  @id = id
  @multiple = multiple
  @accept = accept
  @error = error
  @disabled = disabled
  @required = required
  @full_width = full_width
  @attributes = attributes
  super()
end

Instance Method Details

#view_templateObject



26
27
28
29
30
# File 'lib/forms/file_input.rb', line 26

def view_template
  attrs = binding_attributes(accept: @accept)
  attrs[:multiple] = true if @multiple
  render DaisyUI::FileInput.new(*daisy_modifiers, **attrs)
end