Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Select Callback invoked before a file is selected #585

Closed
benfoster opened this issue Feb 25, 2015 · 5 comments
Closed

File Select Callback invoked before a file is selected #585

benfoster opened this issue Feb 25, 2015 · 5 comments

Comments

@benfoster
Copy link

I recently updated to 3.0.7 and am experiencing a problem I'm pretty sure did not experience prior to the upgrade.

This Plunk demonstrates the issue. The first time the page loads the file selected callback is not invoked until a file is actually selected. If you click the Choose File button again, the callback is invoked immediately. This has the effect of posting an empty files array to the callback which is causing our uploads to fail.

I know I should check the files array before attempting an upload but I was curious if this is the expected behaviour?

@danialfarid
Copy link
Owner

Yes this is the expected behaviour. To be able to cancel the selected file when the user cancels the file select pop up the model will be set to empty when the user clicks on the file upload. This way if you cancel the popup your model will be in sync with the file input.
Here is more details: #525 (comment)

That empty file event could be used to show custom messages or disable the form submission.

@benfoster
Copy link
Author

Thanks for clarifying.

@benfoster
Copy link
Author

@danialfarid we've just upgraded to the latest release and have found that the behaviour described above has changed slightly.

Previously the ngf-change callback was invoked and passed an empty array of files, so we updated all of our handlers like so:

    function uploadMedia(project, files) {

      if (!files.length) {
        return;
      }

Now when we upload a file by clicking the element, then click it again (to upload another file) the callback is invoked passing null.

I could of course update our handlers like so:

function uploadMedia(project, files) {

  if (!files || !files.length) {
    return;
  }

But I just wanted some clarification on the change. Is there any way to prevent the callback from firing when nothing has been selected or will it always be invoked when going from files[] > null.

Thanks

@benfoster benfoster reopened this Dec 23, 2015
@danialfarid
Copy link
Owner

You can specify ng-model-options={updateOn: 'select drop paste'} to exclude click from firing an update, but that would make it behave differently on browsers, for example chrome will empty the files if you cancel the popup, other browser's won't so if you select the same file again they won't fire any change event. So it is better to do the null check to behave the same cross browser.

@benfoster
Copy link
Author

Thanks again for clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants