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

Method to count all current select files #731

Closed
fabioaccetta opened this issue Aug 2, 2016 · 4 comments
Closed

Method to count all current select files #731

fabioaccetta opened this issue Aug 2, 2016 · 4 comments

Comments

@fabioaccetta
Copy link

fabioaccetta commented Aug 2, 2016

I'm using only ajax for upload and delete and I need a method to count all current selected files (both uploadable/deleteable and already uploaded but without errors). Upload is triggered with the filebatchselected event right after files are selected.

If I use $input.fileinput("getFileStack") I don't get the value I expect, as documentation says:

[...] This method will not return files [...] which have already been uploaded.

Shortly, I need a method similar to that one you already use to populate initialCaption inside the <div class="file-caption-name"></div> - previewCache.count(self.id) - to update the div#stack-size with the files count after every upload/delete action, but I can't find anything like that in documentation.

My config with yii2:

[...]
'options' => [
    'multiple' => true,
],
'pluginOptions' => [
    'maxFileCount' => 10,
    'previewFileType' => 'any',
    'initialPreviewAsData' => true,
    'initialPreview' => $initialPreview,
    'initialPreviewConfig' => $initialPreviewConfig,
    'overwriteInitial' => false,
    'uploadUrl' => Url::toRoute(['ajax-file-upload', 'id' => $model->id]),
    'uploadAsync' => false,
],
'pluginEvents' => [
    'filebatchselected' => 'function() {
        $(this).fileinput("upload");
    }',
    'filebatchuploadsuccess' => 'function() {
        var stack = $(this).fileinput("getFileStack"); // <-- not as expected
        var value = stack.length;
        $("#stack-size").html(value);
    }',
    'filedeleted' => 'function() {
        var stack = $(this).fileinput("getFileStack"); // <-- not as expected
        var value = stack.length;
        $("#stack-size").html(value);
    }',
],
[...]
@kartik-v
Copy link
Owner

kartik-v commented Aug 2, 2016

The plugin can only give you client side data... for server side uploaded files - you need to write your logic to calculate the count of files successfully uploaded.

@kartik-v kartik-v closed this as completed Aug 2, 2016
@fabioaccetta
Copy link
Author

Yes, I need only client side data, exactly like your <div class="file-caption-name"></div> that tells (client-side) the number of files currently handled by the plugin.

@kartik-v kartik-v reopened this Aug 2, 2016
@kartik-v
Copy link
Owner

kartik-v commented Aug 2, 2016

This is based on validateInitialCount ... but will check on this.... because it can get changed depending on thumbnail delete.... in either case it will only give you the count... the plugin will have no knowledge of data of files on server.

@fabioaccetta
Copy link
Author

The solution could be a sort of public method like this:

var count = $("#input-id").fileinput("getFilesCount");

available inside the filebatchuploadsuccess and the filedeleted events.

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