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

onclick method working only locally #13

Closed
maxxer opened this issue Apr 24, 2015 · 6 comments
Closed

onclick method working only locally #13

maxxer opened this issue Apr 24, 2015 · 6 comments

Comments

@maxxer
Copy link
Contributor

maxxer commented Apr 24, 2015

I was trying the suggested method to upload files on form submit but it doesn't seem to work. At least it does not on production server.

When I submit a form locally, even with a rather large file (5MB), the upload is very fast so it completes within milliseconds, even before the form submit.

When I do the same on the production server, which is much slower in bandwidth, the file upload starts but the form is submitted at the same time, so when the file send reaches say 5% the page is changed and upload interrupted.

The upload should probably be handled by returning false to the submit, and attach to file-input's filebatchuploadcomplete event in order to finally submit the form.

I tried this solution:

'onclick' => "function (e) {
    e.preventDefault();
    var element = this;
    $('#file-input').on('filebatchuploadcomplete', function(event, files, extra, element) {
        console.log('File batch upload complete');
        $(element).closest("form").submit();
    });

    $('#file-input').fileinput('upload');
};

But it won't work anyway. The upload seems to complete but it's not attached to the model. More details on the forum

@CTOlet
Copy link
Owner

CTOlet commented Apr 26, 2015

I have no free time to help for you now. But I think that you go right way, problem is in onclick event.

@maxxer
Copy link
Contributor Author

maxxer commented Apr 30, 2015

I ended up with something like this in the form:

<?php 
$this->registerJs("
    var formbutton = $('#formsubmit');
    formbutton.on('click', function(e) {
        $('#formsubmit').prop('disabled', true);
        e.preventDefault();
        $('#file-input').fileinput('upload');
    }); 

    $('#file-input').on('filebatchuploadcomplete', function(event, files, extra) {
        document.mioform.submit();
    });
");

Being formbutton the ID of the submit button, and mioform the name of the form.
It still needs some enhancements, upload and validation errors are not handled

@CTOlet
Copy link
Owner

CTOlet commented May 1, 2015

Fixed just now, please update and check how does it work

@maxxer
Copy link
Contributor Author

maxxer commented May 7, 2015

working great, thanks!
a little improvement: disable the submit button while uploading, and reenable in case of errors

@maxxer maxxer closed this as completed May 7, 2015
@maxxer
Copy link
Contributor Author

maxxer commented May 12, 2015

Error check is not perfect... For example if the uploaded files are bigger than max_post_size or max_upload_size an error is displayed in the widget, but the form is submitted anyway

@maxxer maxxer reopened this May 12, 2015
@CTOlet
Copy link
Owner

CTOlet commented Jun 19, 2015

Fixed on f45842c, please test it

@CTOlet CTOlet closed this as completed Jun 19, 2015
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