Here are some examples showcasing file input components.
File inputs allow users to select and upload files.
You can restrict the file types that can be selected using the accept
attribute.
.my-2.flex.flex-col.gap-4
= daisy_label(for: "image", title: "Upload Image")
= daisy_file_input(name: "image", id: "image", accept: "image/*", css: "file-input-bordered")
= daisy_label(for: "pdf", title: "Upload PDF", css: "mt-4")
= daisy_file_input(name: "pdf", id: "pdf", accept: ".pdf", css: "file-input-bordered")
Enable multiple file selection with the multiple
attribute.
File inputs can be styled with additional CSS classes to change their appearance.
.my-2.flex.flex-col.gap-4
= daisy_label(for: "file_primary", title: "Primary File Input")
= daisy_file_input(name: "file_primary", id: "file_primary", css: "file-input-primary file-input-bordered")
= daisy_label(for: "file_secondary", title: "Secondary File Input", css: "mt-4")
= daisy_file_input(name: "file_secondary", id: "file_secondary", css: "file-input-secondary file-input-bordered")
= daisy_label(for: "file_accent", title: "Accent File Input", css: "mt-4")
= daisy_file_input(name: "file_accent", id: "file_accent", css: "file-input-accent file-input-bordered")
File inputs can use the file-input-ghost
class for a minimalist appearance
that only shows borders on hover.
Ghost style with background container:
Ghost style with background container:
.my-2.flex.flex-col.gap-4
= daisy_label(for: "file_ghost", title: "Ghost Style File Input")
= daisy_file_input(name: "file_ghost", id: "file_ghost", css: "file-input-ghost")
.mt-4.p-4.border.rounded-lg.bg-teal-200
%p.text-sm.mb-2 Ghost style with background container:
= daisy_label(for: "file_ghost_bg", title: "Upload Files")
= daisy_file_input(name: "file_ghost_bg", id: "file_ghost_bg", css: "file-input-ghost")
File inputs can be disabled using the disabled
attribute.
File inputs can be marked as required using the required
attribute.
The built-in Form Builder extension provides an easy way to use file inputs in your forms by extracting the name and ID attributes from the form object and attributes.
= form_with(url: "#", method: :post, scope: :user, html: { multipart: true }) do |form|
.my-2.flex.flex-col.gap-4
= form.daisy_label(:avatar)
= form.daisy_file_input(:avatar, css: "file-input-bordered")
= form.daisy_label(:documents, "Upload Documents", css: "mt-4")
= form.daisy_file_input(:documents, multiple: true, css: "file-input-bordered")