Tower File Input

This is a simple JavaScript plugin that works as a UI upgrade to the default HTML file input.


Live Demo

Try picking a single non-image file, multiple files, and a single image file.

Show/Hide Code


Setup

The most basic setup will look like this:

<div class="twr-file">
    <input type="file" id="file1" />
    <label for="file1">
        Select a File
    </label>
</div>
let input = document.getElementByID('file1');
new twrFileInput(input);

The input and the label must be in an element with the class twr-file. The id attribute of the input and the for attribute of the label must match or clicking on the label will not trigger the input.

The class twr-file-button can be used for basic styling on the label or buttons. Remove this class if you are using a different style for the buttons.

You can add a button to clear all of the selected files by adding a button with the class twr-file-clear inside the main element:

<button type="button" class="twr-file-clear twr-file-button">
    Clear
</button>

More Examples


Options
Option Name Default Value Description
showFileList true Toggles showing the list of files if multiple files are selected.
showImgPreview true Toggles showing the preview image if a single image file is selected.
iconClass null The class that will be used in the span before the text in the label when a file is selected. If this is null the span element will not be generated.