Giter Club home page Giter Club logo

Comments (10)

tim-kos avatar tim-kos commented on July 17, 2024

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.

mromagnoli avatar mromagnoli commented on July 17, 2024

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.

tim-kos avatar tim-kos commented on July 17, 2024

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.

mromagnoli avatar mromagnoli commented on July 17, 2024

Yeah, that sounds great! I'm gonna take a look this weekend, for sure.

from jquery-sdk.

bar avatar bar commented on July 17, 2024

Will this be merged into 2.x?

from jquery-sdk.

subakva avatar subakva commented on July 17, 2024

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.

tim-kos avatar tim-kos commented on July 17, 2024

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.

@subakva

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.

mromagnoli avatar mromagnoli commented on July 17, 2024

@tim-kos First of all, congrats for your wedding!
About merging, that sounds cool.

from jquery-sdk.

bar avatar bar commented on July 17, 2024

@tim-kos @subakva +1, keep it neat

from jquery-sdk.

tim-kos avatar tim-kos commented on July 17, 2024

Closing this as processZeroFiles has been merged almost two years ago. I just forgot to close this issue. :/

from jquery-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.