diff --git a/Source/Form.MultipleFileInput.js b/Source/Form.MultipleFileInput.js index fcbc5ec..f834012 100644 --- a/Source/Form.MultipleFileInput.js +++ b/Source/Form.MultipleFileInput.js @@ -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) }; diff --git a/Source/Form.Upload.js b/Source/Form.Upload.js index 88e1312..276da9e 100644 --- a/Source/Form.Upload.js +++ b/Source/Form.Upload.js @@ -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), @@ -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() { @@ -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 = [];