Skip to content

Commit a3a3717

Browse files
author
Federico Zivolo
committed
added file input support
1 parent ccda618 commit a3a3717

5 files changed

Lines changed: 61 additions & 2 deletions

File tree

css-compiled/material.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,17 @@ select.form-control.focus {
17981798
opacity: 0;
17991799
}
18001800
}
1801+
.form-control-wrapper input[type=file] {
1802+
opacity: 0;
1803+
position: absolute;
1804+
top: 0;
1805+
right: 0;
1806+
bottom: 0;
1807+
left: 0;
1808+
width: 100%;
1809+
height: 100%;
1810+
z-index: 100;
1811+
}
18011812
legend {
18021813
border-bottom: 0;
18031814
}

demo/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,13 @@ <h1 id="forms">Forms</h1>
12841284
</div>
12851285
</div>
12861286
</div>
1287+
<div class="form-group">
1288+
<label for="inputFile" class="col-lg-2 control-label">File</label>
1289+
<div class="col-lg-10">
1290+
<input type="text" readonly class="form-control floating-label" placeholder="Browse...">
1291+
<input type="file" id="inputFile" multiple>
1292+
</div>
1293+
</div>
12871294
<div class="form-group">
12881295
<label for="textArea" class="col-lg-2 control-label">Textarea</label>
12891296
<div class="col-lg-10">

less/inputs.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,17 @@ select.form-control {
205205
@-ms-keyframes input-highlight {.keyframe-input-highlight()}
206206
@-o-keyframes input-highlight {.keyframe-input-highlight()}
207207
@keyframes input-highlight {.keyframe-input-highlight()}
208+
209+
210+
// Input files (kinda hack)
211+
.form-control-wrapper input[type=file] {
212+
opacity: 0;
213+
position: absolute;
214+
top: 0;
215+
right: 0;
216+
bottom: 0;
217+
left: 0;
218+
width: 100%;
219+
height: 100%;
220+
z-index: 100;
221+
}

less/test.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Generated by less 1.7.0 */
1+
/* Generated by less 1.7.5 */
22
.btn-default {
33
color: #000000;
44
}

scripts/material.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ $(function (){
2222
if ($(this).val() === "") {
2323
$(this).addClass("empty");
2424
}
25+
26+
if ($(this).parent().next().is("[type=file]")) {
27+
$(this).parent().addClass("fileinput");
28+
var $input = $(this).parent().next().detach();
29+
$(this).after($input);
30+
}
2531
});
2632

2733
$(document).on("keyup change", ".form-control", function() {
@@ -31,8 +37,29 @@ $(function (){
3137
$(this).addClass("empty");
3238
}
3339
});
34-
$(document).on("keydown", ".form-control", function() {
40+
$(document).on("keydown change", ".form-control", function() {
3541
$(this).removeClass("empty");
3642
});
43+
$(document)
44+
.on("focus", ".form-control-wrapper.fileinput", function() {
45+
$(this).find("input").addClass("focus");
46+
})
47+
.on("blur", ".form-control-wrapper.fileinput", function() {
48+
$(this).find("input").removeClass("focus");
49+
})
50+
.on("change", ".form-control-wrapper.fileinput [type=file]", function() {
51+
var value = "";
52+
$.each($(this)[0].files, function(i, file) {
53+
console.log(file);
54+
value += file.name + ", ";
55+
});
56+
value = value.substring(0, value.length - 2);
57+
if (value) {
58+
$(this).prev().removeClass("empty");
59+
} else {
60+
$(this).prev().addClass("empty");
61+
}
62+
$(this).prev().val(value);
63+
});
3764
});
3865

0 commit comments

Comments
 (0)