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

onchange is not triggered when cancel a file input #527

Closed
wuv1982 opened this issue Jan 29, 2015 · 6 comments
Closed

onchange is not triggered when cancel a file input #527

wuv1982 opened this issue Jan 29, 2015 · 6 comments

Comments

@wuv1982
Copy link

wuv1982 commented Jan 29, 2015

first i selected a file, not use drag&drop, then i remove it by cancel a input .
the ng-model value should be empty, but it didn't changed because change event is not triggered.

if i removed this part, the problem will be solved.

if ($parse(attr.resetOnClick)(scope) != false) {
        if (navigator.appVersion.indexOf("MSIE 10") !== -1) {
            // fix for IE10 cannot set the value of the input to null programmatically by replacing input
            var replaceElem = function(evt) {
                var inputFile = elem.clone();
                inputFile.val('');
                elem.replaceWith(inputFile);
                $compile(inputFile)(scope);
                fileElem = inputFile;
                elem = inputFile;
                elem.bind('change', onChangeFn);
                elem.unbind('click');
                elem[0].click();
                elem.bind('click', replaceElem);
                evt.preventDefault();
                evt.stopPropagation();
            };
            elem.bind('click', replaceElem);
        } else {
            elem.bind('click', function(evt) {
                elem[0].value = null;
            });
        }
    }

i dont known whether there is anything wrong with here?

your Demo has same problem, so you can reproduce it.

@danialfarid
Copy link
Owner

This part is to support cancel for browsers other than chrome. How removing it would make it work!

@wuv1982
Copy link
Author

wuv1982 commented Jan 30, 2015

sorry for not give you more details. here is it.

browser

Chrome Mac 40.0.2214.93 (64-bit)

html

<input type="file" ng-multiple="true" ng-file-select ng-model="upload.files" />

js

$scope.$watch 'upload.files', (n, o) ->
        $log.log "watch changed to: ", n

screenshot

2015-01-30 12 11 45

canceled by Red Rectangle part in pic.
it gave me a log when i selected one file, but not gave anything when i canceled the input

@danialfarid
Copy link
Owner

What version of the plugin? Is it happening on the demo page too?

@wuv1982
Copy link
Author

wuv1982 commented Jan 30, 2015

angular-file-upload : 2.2.2
angular : 1.3.11


In your demo, $scope.generateThumb is triggered when select ,but not triggered when cancel.

@danialfarid
Copy link
Owner

This should be fixed in version 3.0.0.
When you click on the file select the value is set to null so if the user cancels the popup and don't select another file your model is already set to null.

@wuv1982
Copy link
Author

wuv1982 commented Feb 4, 2015

nice update.
expect for the release.

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