Class: Trestle::Form::Fields::FileField

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/file_field.rb

Instance Attribute Summary

Attributes inherited from Trestle::Form::Field

#block, #builder, #name, #options, #template

Instance Method Summary collapse

Methods inherited from Trestle::Form::Field

#defaults, #errors, #form_group, #initialize, #normalize_options!, #readonly?, #render

Constructor Details

This class inherits a constructor from Trestle::Form::Field

Instance Method Details

#browse_textObject


24
25
26
# File 'lib/trestle/form/fields/file_field.rb', line 24

def browse_text
  I18n.t("trestle.file.browse", default: "Browse")
end

#choose_file_textObject


20
21
22
# File 'lib/trestle/form/fields/file_field.rb', line 20

def choose_file_text
  I18n.t("trestle.file.choose_file", default: "Choose file")
end

#custom?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/trestle/form/fields/file_field.rb', line 16

def custom?
  options[:custom] != false
end

#fieldObject


5
6
7
8
9
10
11
12
13
14
# File 'lib/trestle/form/fields/file_field.rb', line 5

def field
  if custom?
    (:div, class: "custom-file") do
      concat builder.raw_file_field(name, options.merge(class: "custom-file-input"))
      concat builder.label(name, choose_file_text, class: "custom-file-label", data: { browse: browse_text })
    end
  else
    builder.raw_file_field(name, options)
  end
end