Skip to content

Commit

Permalink
FireAtOnce also works if on the change event
Browse files Browse the repository at this point in the history
  • Loading branch information
arian committed Jul 9, 2012
1 parent 2d9de4e commit 4e5f099
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Source/Form.MultipleFileInput.js
Expand Up @@ -46,8 +46,9 @@ Form.MultipleFileInput = new Class({
input.set('multiple', true);

this.inputEvents = {
change: function(){
change: function(event){
Array.each(input.files, this.add, this);
this.fireEvent('change', event);
}.bind(this)
};

Expand Down
39 changes: 24 additions & 15 deletions Source/Form.Upload.js
Expand Up @@ -58,17 +58,6 @@ Form.Upload = new Class({
var progress = new Element('div.progress')
.setStyle('display', 'none').inject(list, 'after');

var inputFiles = new Form.MultipleFileInput(input, list, drop, {
onDragenter: drop.addClass.pass('hover', drop),
onDragleave: drop.removeClass.pass('hover', drop),
onDrop: function(){
drop.removeClass.pass('hover', drop);
if (self.options.fireAtOnce){
form.fireEvent("submit");
}
}
});

var uploadReq = new Request.File({
url: form.get('action'),
onRequest: progress.setStyles.pass({display: 'block', width: 0}, progress),
Expand All @@ -85,12 +74,25 @@ Form.Upload = new Class({

var inputname = input.get('name');

var inputFiles = new Form.MultipleFileInput(input, list, drop, {
onDragenter: drop.addClass.pass('hover', drop),
onDragleave: drop.removeClass.pass('hover', drop),
onDrop: function(){
drop.removeClass.pass('hover', drop);
if (self.options.fireAtOnce){
self.submit(inputFiles, inputname, uploadReq);
}
},
onChange: function(){
if (self.options.fireAtOnce){
self.submit(inputFiles, inputname, uploadReq);
}
}
});

form.addEvent('submit', function(event){
if (event) event.preventDefault();
inputFiles.getFiles().each(function(file){
uploadReq.append(inputname , file);
});
uploadReq.send();
self.submit(inputFiles, inputname, uploadReq);
});

self.reset = function() {
Expand All @@ -101,6 +103,13 @@ Form.Upload = new Class({
};
},

submit: function(inputFiles, inputname, uploadReq){
inputFiles.getFiles().each(function(file){
uploadReq.append(inputname , file);
});
uploadReq.send();
},

legacyUpload: function(input){

var rows = [];
Expand Down

0 comments on commit 4e5f099

Please sign in to comment.