Comments (10)
Hey there,
yeah this is what processZeroFiles does. When set to false and no file is selected, it submits the form just as if Transloadit wasn't bound on the page at all.
I guess another option would be nice to not allow submission of the form at all. But I think that is app-level logic. Hm, not sure. What do you think?
from jquery-sdk.
Hi Tim, I've just been writing you in support.
So that what it does, I was wondering a use case when this will be useful, and I believe you did it like this for the situation when you have forms with other input elements and a user submits even if no file is selected, that is one case. But this could not work if action to api2.transloadit.com/assemblies is setted and autoSubmit property is setted to false, so if submitForm unbinds submit.transloadit I will be posting to transloadit empty files and redirecting user.
Is there any use case that I'm not bearing in mind?
I believe it should be an option where I can define whether submit or not on empty file input.
from jquery-sdk.
Hey,
sorry for the delay in getting back to you. I think what you propose makes sense.
Do you mind thinking of a name for that new option and submit a pull request for the change? I'd be glad to review and merge it.
from jquery-sdk.
Yeah, that sounds great! I'm gonna take a look this weekend, for sure.
from jquery-sdk.
Will this be merged into 2.x
?
from jquery-sdk.
I've been trying to get the same behavior for an upload form with additional fields. I want file selection to trigger an upload, but I don't want form submission to trigger an upload. I think I've found a workaround for that use case that doesn't require hacking the script.
I define my own change listener on the file input. When the user selects a file, the change event is triggered, which initializes the transloadit plugin, then manually triggers the submit.transloadit
event. The transloadit plugin callbacks are then configured to unbind the submit.transloadit
event from the form. Form submission always works as if the transloadit plugin was not there, but choosing a file will still upload and update the form with the assembly results.
var bindTransloadit = function(form) {
form.transloadit({
wait: true,
modal: true,
triggerUploadOnFileSelection: false,
processZeroFiles: false,
autoSubmit: false,
onStart: function(assembly) {
// remove any outdated assembly results
form.find('textarea[name=transloadit]').remove();
},
onUpload: function(upload) {
$('.image-preview').attr('src', upload.url).show();
},
onCancel: function() { form.unbind('submit.transloadit'); },
onError: function(assembly) { form.unbind('submit.transloadit'); },
onSuccess: function(assembly) { form.unbind('submit.transloadit'); }
});
};
$('.upload-among-other-things-form').on('change', 'input[type="file"]', function() {
var form = $(this).closest('form');
bindTransloadit(form);
form.trigger('submit.transloadit');
});
from jquery-sdk.
Hey @bar
Sorry for the delay again, but I have been on my honeymoon. Yes, the option is going to merged into the 2.x branch.
Hm that's neat. I wonder if we should also add this to the plugin and make it an option, i.e. triggerUploadOnlyOnFileSelection or something.
from jquery-sdk.
@tim-kos First of all, congrats for your wedding!
About merging, that sounds cool.
from jquery-sdk.
@tim-kos @subakva +1, keep it neat
from jquery-sdk.
Closing this as processZeroFiles
has been merged almost two years ago. I just forgot to close this issue. :/
from jquery-sdk.
Related Issues (20)
- Document title set to null when complete HOT 1
- $el.transloadit('start'); not working HOT 2
- A failed assembly triggers a file upload to our servers HOT 2
- debug option has no effect HOT 2
- onSuccess called instead of onError callback HOT 3
- Is there an unpacked version? HOT 1
- Include signature field when using FormData HOT 2
- Uploader.start() should gracefully handle when files are null HOT 3
- clone input when using formData HOT 1
- npm && CommonJS support HOT 4
- BORED_INSTANCE_ERROR HOT 1
- v3: Drag&Drop onFileSelect callback behaves in an undocumented way. HOT 3
- V3: this._modal.renderCancelling() is still invoked when modal is set to false. HOT 1
- v3: Assumes global $, does not play well with Browserify and ES6 modules HOT 12
- Removed function Assembly.stopStatusFetching is still being called. HOT 1
- this.$ is not a function HOT 1
- Add timeouts for internet connection tests HOT 1
- Release new version to NPM? HOT 6
- maxNumberOfUploadedFiles - Error still returned on subsequent upload attempts even within allowable limits. HOT 16
- Unexpected token ':' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-sdk.