Sha256: 955e15f7e6e6487a8a2652907e63d2e132bc2e812bd9f0facf54d8d65cddd100

Contents?: true

Size: 875 Bytes

Versions: 5

Compression:

Stored size: 875 Bytes

Contents

module Trestle
  class Form
    module Fields
      class FileField < Field
        def field
          if custom?
            content_tag(: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

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

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

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

Trestle::Form::Builder.register(:file_field, Trestle::Form::Fields::FileField)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trestle-0.9.8 lib/trestle/form/fields/file_field.rb
trestle-0.9.7 lib/trestle/form/fields/file_field.rb
trestle-0.9.6 lib/trestle/form/fields/file_field.rb
trestle-0.9.5 lib/trestle/form/fields/file_field.rb
trestle-0.9.4 lib/trestle/form/fields/file_field.rb