Skip to the page content

Fields that take files

Upload fields for single files, images, attachments and large imports, with checks before anything is sent.

9 fields

Sortable image gallery

Several images in one field, previewed before anything uploads. Drag a photo, or use its Move buttons, to reorder; the first one is the cover. Each photo takes alt text, and type, size and count are checked as files arrive.

Image upload
Show code
<input type="file" id="gal-input" accept="image/jpeg,image/png,image/webp" multiple>

// A preview without uploading: an object URL points straight at the file.
img.src = URL.createObjectURL(file);
// Reorder by dragging, or with the Move buttons for keyboard users.
list.insertBefore(dragged, target.nextSibling);

Single image with replace

One file that replaces the last, with a thumbnail, name and size. The image is opened to read its pixel size, and anything under 300 px wide gets a warning. You can also drop a file onto it.

Single file
Show code
<input type="file" id="logo-input" accept="image/png,image/svg+xml,image/jpeg">

// Read the pixel size before accepting it.
const img = new Image();
img.onload = () => warn(img.naturalWidth < 300);
img.src = URL.createObjectURL(file);

Textarea with paste and drop

A text box that also takes files. Attach with the paperclip, drop files onto the box, or paste a screenshot straight in. Files show as removable chips under the text, each capped at 10 MB.

Attachments

    Paste a screenshot, or drop files here. 10 MB at most.

    Show code
    textarea.addEventListener('paste', (e) => {
      const files = [...e.clipboardData.files];
      if (files.length) { e.preventDefault(); files.forEach(attach); }
    });
    box.addEventListener('drop', (e) => { e.preventDefault(); [...e.dataTransfer.files].forEach(attach); });

    Avatar with crop and zoom

    One image cropped to a circle before saving. Zoom with the slider, then drag or use the arrow keys to position it, with live previews at three sizes. The crop is saved as a new file.

    Image upload

    Use the arrow keys to move the photo inside the circle.

    • Replies
    • Menu
    • Lists

    Square works best. JPG, PNG or WebP, at least 200 px across.

    Show code
    const img = await createImageBitmap(file);
    ctx.drawImage(img, x, y, img.width * scale, img.height * scale);
    canvas.toBlob((blob) => form.append('photo', blob), 'image/jpeg', .9);

    Required file slots

    A list of named slots, one file each, for when you need specific documents. Every slot has its own accepted types and states: needed, optional, uploading, ready or refused. The list can change with another answer, and submitting shows what is missing.

    Validation
    Slots shown for

    0 of 3 ready

    • Business registration

      PDF, up to 10 MB. The page with your trading name on it.

      Needed
    • Proof of address

      PDF, JPG or PNG. A utility bill or lease from the last three months.

      Needed
    • Care registration

      PDF, JPG or PNG. Your current care license, front and back.

      Needed
    • Your price list

      Optional. We load it so your first estimates use your own prices.

      Optional

    We reply within two working days.

    Show code
    <li class="upload-slot" data-slot="license" data-accept="pdf">
      <p id="doc-license-hint">PDF, up to 10 MB.</p>
      <p id="doc-license-error" hidden></p>
      <input type="file" id="doc-license" accept=".pdf"
             aria-describedby="doc-license-hint doc-license-error">
      <label for="doc-license" class="btn btn-outline-secondary btn-sm">Choose file</label>
    </li>

    Type, size and count limits

    A required multi-file field that checks every file as it is added. Wrong types, files over 2 MB and anything past the third are refused with the reason, and submitting it empty shows an error summary.

    Validation

    Photos of the damaged parcel

        Want to see a refusal? or

        Show code
        const OK = ['image/jpeg', 'image/png', 'application/pdf'];
        const why = (f) =>
          !OK.includes(f.type) ? `${ext(f)} files are not accepted`
          : f.size > 2 * MB   ? `${size(f)} is over the 2 MB limit`
          : list.length >= 3  ? 'This field takes three photos at most' : null;

        Chunked, resumable upload

        For files too big to send in one go. The file is sliced into pieces of a size you set, with progress, speed and time left. Pause, or drop the connection on purpose, and it carries on from the last good piece.

        Large file

        new-starter-safety-training.mp4

        480 MB

        48 pieces

        0%

        Sent
        0 of 480 MB
        Speed
        Not started
        Time left
        About 30 s

        Ready when you are.

        Show code
        for (let i = done; i < pieces; i++) {
          const part = file.slice(i * size, (i + 1) * size);
          await sendWithRetry(part, { index: i, uploadId });  // resumes from here
          done = i + 1;
        }

        CSV import with column mapping

        A three-step import for a spreadsheet. Columns are matched by name and can be changed, each row is checked before anything is saved, and a switch decides whether rows with gaps are skipped.

        Import
        1. 1Choose a file
        2. 2Match columns
        3. 3Import

        No file to hand?

        Show code
        const text = await file.text();
        const [head, ...rows] = parseCsv(text);           // handles "quoted, fields"
        const guess = (field) => head.findIndex((h) => field.words.some((w) => h.toLowerCase().includes(w)));
        const problems = rows.map((r) => fields.filter((f) => !f.check(r[map[f.key]])));

        Native file input

        Bootstrap's .form-control on a plain type="file". No script needed. Shown with accept, multiple, required and disabled states, and in small and large sizes.

        Native input

        PDF only. Attached to the purchase order.

        Hold Shift or Ctrl to pick more than one.

        Choose the signed agreement to continue.

        Locked while the order is with the courier.

        Show code
        <label for="invoice" class="form-label">Supplier invoice</label>
        <input class="form-control" type="file" id="invoice" accept=".pdf" aria-describedby="ivc-help">
        <p id="ivc-help">PDF only.</p>
        <!-- form-control-sm / -lg for sizes, multiple for several files -->