-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Don't call ngf-change with an empty files parameter #764
Comments
Notice that, when you select over sized files (using the optional |
I have explained here why it needs to be fired on click: #761 (comment) |
There is no reason to call ngf-change with an empty files parameter. Nothing has changed. |
It would only call it if a file is already selected and it resets the model value to null. |
Maybe I need to submit a pull request cause you don't seem to understand. Whatever the expression is in |
If you cancel the popup file select, it should call ngf-change with null value. |
"If you cancel the popup file select, it should call ngf-change with null value." No, it shouldn't. A cancel should not modify state. If there was a value there before, it will be cleared out and that is against the previous sentence. |
Right, that just goes to show that your API design has issues. |
Yea I explained here #761 (comment) that there is no way to detect user's cancel, that's why we need to reset the value on click. |
Call another method. pseudo code:
|
I think that makes it more complicated, ngf-change needs to be close to ng-model behaviour, when you cancel the popup ng-model is being set to null so ngf-change should be called too. |
Right, but the problem is that ngf-change gets called in 3 different situations and for 3 different reasons. Open, Cancel and File Select. That is impossible to case for correctly. |
So what is your suggestion here?
any other solutions you have in mind? |
I have added |
"Setting ngf-reset-model-on-click will not reset the model when you click on the file select, that would make reseting model when the user cancels the select popup impossible in some browsers." Your defaults are conceived in a backwards fashion. By default, you don't want to reset the model on cancel. It is a cancel event, nothing should change. |
Setting it to true by default will break cross browser support. |
Oh right. The option that you'd had to close 20 issues over is a much better default.
|
Had the same issue- In controller- |
2017 update: I have a form that is set up to validate on whether or not a file was uploaded. When a user would cancel out of the dialog box, the upload field would be invalid because the ng-model had changed to null. Since the API has since changed from the suggestions in this issue but this page is still the top result when searching "ng-file-upload change empty," I figured I'd note my solution: I simply hooked into the ngf-before-model-change function, set a temporary controller variable, and reset my "real" value when ngf-change was called. It looks a little like this: form.html
controller.js
Now, the ng-model variable ctrl.file is either a real file (the user selected one in the dialog) or the file it was previously (the user cancels out of the box). |
@danialfarid What I'm seeing is that ngf-change is being called TWICE. Once when you click the button and the file chooser dialog opens and once when the dialog closes after selecting a file.
I added this to your fiddle...
Whatever is calling it shouldn't call it the first time. There is no reason to call $scope.upload if files is null. This would allow me to remove the null check and simplify things greatly.
The text was updated successfully, but these errors were encountered: