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

Reset on browse? #53

Closed
jespermjonsson opened this issue Nov 18, 2014 · 6 comments
Closed

Reset on browse? #53

jespermjonsson opened this issue Nov 18, 2014 · 6 comments

Comments

@jespermjonsson
Copy link
Contributor

What is the reason for resetting the fileupload when clicking on the browse button? If the user then decides to cancel the file dialog the current selected file is lost. I tested to uncomment self.clear(false) within the listen method and everything seems to be working, but maybe not in some edge case(s)?

listen: function () {
    var self = this, $el = self.$element, $cap = self.$captionContainer, $btnFile = self.$btnFile;
    $el.on('change', $.proxy(self.change, self));
    $(window).on('resize', function() {
        setTimeout(function() {
            self.autoSizeCaption();
        }, 100);  
    });
    $btnFile.on('click', function (ev) {
        self.clear(false); // <-----
        $cap.focus();
    });
    $el.closest('form').on('reset', $.proxy(self.reset, self));
    self.$container.on('click', '.fileinput-remove:not([disabled])', $.proxy(self.clear, self));
},
@jespermjonsson
Copy link
Contributor Author

Sorry, I just missed to set overwriteInitial to false...

@jespermjonsson
Copy link
Contributor Author

Actually that didn't fix the problem, the upload just resets to the initial overwrite. Any other selected files is removed by the clear method when hitting upload the next time. So I still wonder why the upload is cleared when clicking the browse button.

@kartik-v
Copy link
Owner

I hope you understand the reason for the expected behavior.

The HTML native file input can push data only one way. It cannot read or edit older data like other HTML inputs. You need to handle such situations separately (beyond the scope of this extension). However, the plugin does help you with events, customizing layouts, adding new buttons, to handle such custom scenarios.

With regards, why the older file selection is cleared when you click browse button ... refer issue #19.

Its the inherent behavior of the HTML native file input which automatically clears the files selected whenever you click the input and cancel the file dialog.

Hence the selected file preview is cleared for this reason. If this is NOT DONE you will end up with an empty $_FILES array on form submission - but preview shows the old image. Its done for a logical reason to mimic the HTML file input functionality (unfortunately the plugin is limited by HTML file input functionality at this stage).

@jespermjonsson
Copy link
Contributor Author

Ok I understand, didn't know that the native file input was cleared when the file dialog was shown. I'll rethink the UI then, thanks!

@jespermjonsson
Copy link
Contributor Author

Would you be open to adding an event for when the file input changes from having a file to being empty like I have done here: jespermjonsson@97728b2
By adding that I'm able to keep the UI unchanged during fileselection and wait either for the fileselect event or this new event.

@kartik-v
Copy link
Owner

Will consider this as an enhancement.

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

No branches or pull requests

2 participants