Use up and down keys to navigate results once you've typed more than two characters. Use the enter key to select a result. Touch device users, explore by touch or with swipe gestures.
Upload
Overview
A file upload input allows a user to select a file from their computer's file system.
<div class="ons-field">
<div class="ons-field">
<label class="ons-label ons-label--with-description" for="file-example-upload"
aria-describedby="description-hint">Upload a file</label>
<span id="description-hint" class="ons-label__description ons-input--with-description">File types accepted are XLS
and XLSX or PDF</span>
<input type="file" id="file-example-upload"
class="ons-input ons-input--text ons-input-type__input ons-input--upload" accept=".xls,.xlsx,.pdf"
aria-describedby="description-hint" />
</div>
</div>
When to use this component
Use this component when there is a requirement for a user to select and submit a local file as part of their task.
How to use this component
The <input> value is set to type="file". A file upload input also takes the attribute accepts= which take a comma separated list of file extensions with the . prefix for example: accept=".xls,.xlsx,.pdf".
How to check uploads
To help users upload a file, you should:
check they have uploaded something
check that what they have uploaded is a valid file type
show an error message if they have not uploaded anything or what they have uploaded is not a valid file type
{% from "components/upload/_macro.njk" import onsUpload %}
{{
onsUpload({
"id": "file-example-upload-error",
"accept": ".xls,.xlsx,.pdf",
"label": {
"description": "File types accepted are XLS and XLSX or PDF",
"text": "Upload a file"
},
"error": {
"id": "file-error",
"text": "Select a file that is an XLS, XLSX or PDF"
}
})
}}
Nunjucks macro options
Name
Type
Required
Description
id
string
true
The HTML id of the upload input. Sets the HTML for attribute on the label.