Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
add id attr support. add slot support. add label wrapper on input for…
Browse files Browse the repository at this point in the history
… styling
  • Loading branch information
james2doyle committed Dec 9, 2015
1 parent 5bbb2eb commit cea94f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<div class="progress-bar" style="width: {{ fileProgress }}%" v-show="fileProgress > 0" ></div>
<!-- message for all uploads completing -->
<p v-if="allFilesUploaded"><strong>All Files Uploaded</strong></p>
<!-- multiple files usage -->
<file-upload class="my-file-uploader" name="myFile" action="upload.php" multiple></file-upload>
<!-- usage for single files -->
<!-- full usage example -->
<file-upload class="my-file-uploader" name="myFile" id="myCustomId" action="upload.php" multiple>Inside Slot Text</file-upload>
<!-- minimal usage -->
<file-upload name="anotherFile" action="upload.php"></file-upload>
</div>
<script src="http://cdn.jsdelivr.net/vue/1.0.10/vue.min.js"></script>
Expand Down
6 changes: 4 additions & 2 deletions vue.file-upload.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* globals FormData, Promise, Vue */
// define
var FileUploadComponent = Vue.extend({
template: '<div class="{{ class }}"><input type="file" name="{{ name }}" id="{{ name }}" accept="{{ accept }}" v-on:click="fileInputClick" v-on:change="fileInputChange" multiple="{{ multiple }}"><button type="button" v-on:click="fileUpload">Upload</button></div>',
template: '<div class="{{ class }}"><label for="{{ name }}"><input type="file" name="{{ name }}" id="{{ id || name }}" accept="{{ accept }}" v-on:click="fileInputClick" v-on:change="fileInputChange" multiple="{{ multiple }}"><slot></slot></label><button type="button" v-on:click="fileUpload">Upload</button></div>',
props: {
class: String,
name: {
type: String,
required: true
},
id: String,
action: {
type: String,
required: true
Expand All @@ -28,7 +29,8 @@ var FileUploadComponent = Vue.extend({
},
fileInputChange: function() {
// get the group of files assigned to this field
this.myFiles = document.getElementById(this.name).files;
var ident = this.id || this.name
this.myFiles = document.getElementById(ident).files;
this.$dispatch('onFileChange', this.myFiles);
},
_onProgress: function(e) {
Expand Down

0 comments on commit cea94f4

Please sign in to comment.