0

I have created my own fileuploader base on magento component. I want to check file number when it reach to limit

define(
[
    'Magento_Ui/js/lib/validation/validator',
    'Magento_Ui/js/form/element/file-uploader',
    'ko'
],
function (
    validator,
    UpLoader,
    ko
) {
    return UpLoader.extend({
        defaults: {
            template: 'uploader/uploader',
            previewTmpl: 'uploader/preview',
            isMultipleFiles : true,
            inputName: 'image',
            uploaderConfig: {
                dataType: 'json',
                sequentialUploads: true,
                formData: {
                    'form_key': window.FORM_KEY
                }
            },
            links: {
                value: '${ $.parentName }:uploadValue'
            }
        },

        //more functions here
        Parent file have lot functions here


        /**
         * This is my constructor
         * Invokes initialize method of parent class,
         * contains initialization logic
         */
        initialize: function () {
            _.bindAll(this, 'reset');
            this._super()
                .setInitialValue()
                ._setClasses()
                .initSwitcher();

            return this;
        },

        /**
         *  Retrieve max number file allow in configuration
         */
        getMaxFileNumber: function() {
            return this.uploaderConfig.maxFileNumber;
        },
    });
});

Is there a good way to check and return alert message when user number file uploaded reach to limit

0

Maybe someone will need, i will post my temporary solution here

onFilesChoosed: function () {
    var files = this.value();
    if (files.length >= this.getMaxFileNumber()) {
        alert("Max files exceeded, You can't upload more!");
        return false;
    }
    return this;
},

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.