Skip to content

Commit 5b94bed

Browse files
committed
feat: allow to set custom attributes for input
1 parent ae159b8 commit 5b94bed

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ parameter must be adjusted together with `progressCallbacksInterval` parameter.
132132

133133
#### Methods
134134

135-
* `.assignBrowse(domNodes, isDirectory, singleFile)` Assign a browse action to one or more DOM nodes. Pass in `true` to allow directories to be selected (Chrome only, support can be checked with `supportDirectory` property).
136-
To prevent multiple file uploads set singleFile to true.
135+
* `.assignBrowse(domNodes, isDirectory, singleFile, attributes)` Assign a browse action to one or more DOM nodes.
136+
* `domNodes` array of dom nodes or a single node.
137+
* `isDirectory` Pass in `true` to allow directories to be selected (Chrome only, support can be checked with `supportDirectory` property).
138+
* `singleFile` To prevent multiple file uploads set this to true. Also look at config parameter `singleFile`.
139+
* `attributes` Pass object of keys and values to set custom attributes on input fields.
140+
For example, you can set `accept` attribute to `image/*`. This means that user will be able to select only images.
141+
Full list of attributes: http://www.w3.org/TR/html-markup/input.file.html#input.file-attributes
137142
Note: avoid using `a` and `button` tags as file upload buttons, use span instead.
138143
* `.assignDrop(domNodes)` Assign one or more DOM nodes as a drop target.
139144
* `.on(event, callback)` Listen for event from Flow.js (see below)

src/flow.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,12 @@
344344
* @param {Element|Array.<Element>} domNodes
345345
* @param {boolean} isDirectory Pass in true to allow directories to
346346
* @param {boolean} singleFile prevent multi file upload
347+
* @param {Object} attributes set custom attributes:
348+
* http://www.w3.org/TR/html-markup/input.file.html#input.file-attributes
349+
* eg: accept: 'image/*'
347350
* be selected (Chrome only).
348351
*/
349-
assignBrowse: function (domNodes, isDirectory, singleFile) {
352+
assignBrowse: function (domNodes, isDirectory, singleFile, attributes) {
350353
if (typeof domNodes.length === 'undefined') {
351354
domNodes = [domNodes];
352355
}
@@ -379,6 +382,9 @@
379382
if (isDirectory) {
380383
input.setAttribute('webkitdirectory', 'webkitdirectory');
381384
}
385+
each(attributes, function (value, key) {
386+
input.setAttribute(key, value);
387+
});
382388
// When new files are added, simply append them to the overall list
383389
var $ = this;
384390
input.addEventListener('change', function (e) {

0 commit comments

Comments
 (0)