File Uploads
Single File
Default
By default, file upload element is used to allow users uploading a single file.
An example case will be using this element to upload a file to be imported as happens on Hustle and Forminator plugins.
An example case will be using this element to upload a file to be imported as happens on Hustle and Forminator plugins.
<div class="sui-form-field"> <label class="sui-label">Field label</label> <div class="sui-upload sui-file-upload sui-file-browser"> <input type="file" value="" readonly="readonly" /> <button class="sui-upload-button" <span class="sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> <div class="sui-upload-file"> <span></span> <button aria-label="Remove file"> <span class="sui-icon-close" aria-hidden="true"></span> </button> </div> </div> <span class="sui-description">Element description.</span> <div class="sui-notice sui-notice-error" style="margin-top: 5px; display: none;"> <p>Element error message.</p> </div> </div>
example-file.pdf
<div class="sui-form-field"> <label class="sui-label">Field label</label> <div class="sui-upload sui-has_file"> <input type="file" value="file-name.txt" readonly="readonly" /> <button class="sui-upload-button" <span class="sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> <div class="sui-upload-file"> <span>file-name.txt</span> <button aria-label="Remove file"> <span class="sui-icon-close" aria-hidden="true"></span> </button> </div> </div> <span class="sui-description">Here goes field description.</span> <div class="sui-notice sui-notice-error" style="margin-top: 5px; display: none;"> <p>Element error message.</p> </div> </div>
Notice when a file is added sui-upload element has sui-has_file
class. We also load uploaded file name to input value and <span></span>
inside sui-upload-file element.
Whoops, only .pdf and .doc filetypes are allowed.
<div class="sui-form-field"> <label class="sui-label">Field label</label> <div class="sui-upload sui-has_file"> <input type="file" value="file-name.txt" readonly="readonly" /> <button class="sui-upload-button" <span class="sui-icon-upload-cloud" aria-hidden="true"></span> Upload file </button> <div class="sui-upload-file"> <span>file-name.txt</span> <button aria-label="Remove file"> <span class="sui-icon-close" aria-hidden="true"></span> </button> </div> </div> <span class="sui-description">Here goes field description.</span> <div class="sui-notice sui-notice-error" style="margin-top: 5px;"> <p>Element error message.</p> </div> </div>
When there's an error notice we remove display: none
inline styles from sui-notice element.
Image Preview
There are times, when uploading images, that you gonna need to preview the uploaded file reason why you will have to add an extra element into Default file upload element.
An example case will be using this element to upload a featured image into your Hustle module.
An example case will be using this element to upload a featured image into your Hustle module.
example-image.jpg
Whoops, only .png and .jpg filetypes are allowed.
<div class="sui-upload sui-file-upload sui-file-browser"> <input type="file" ... /> <!-- NOTE: Insert the element after input but before upload button. --> <div class="sui-upload-image" aria-hidden="true"> <div class="sui-image-mask"></div> <!-- NOTE: Use the uploaded image URL as background image of the div below. Leave empty when no file has been uploaded yet. --> <div role="button" class="sui-image-preview" style="background-image: url();" ></div> </div> <button class="sui-upload-button"> ... </button> <div class="sui-upload-file"> ... </div> </div>