Krajee Bootstrap file input dynamic maxFilecount

Krajee Bootstrap file input dynamic maxFilecount

本文关键字:dynamic maxFilecount input file Bootstrap Krajee      更新时间:2023-09-26

如果输入字段更改,我想用动态数字设置maxFileCount

我的代码:

<input value="" name="check_nums" class="check_nums">

Krajee fileinput:

$(document).on('ready', function() {
    $('#file-th').fileinput({
        var check_nums = $(".check_nums").val();
        showUploadedThumbs: false,
        language: 'th',
        uploadAsync: false,
        maxFileCount: [check_nums],
        resizePreference: 'height',
        resizeImage: true,
        overwriteInitial: false,
        validateInitialCount: true,
        showUpload: false,
        allowedFileExtensions: ['jpg', 'png', 'jpeg'],
        previewSettings: {
            image: {width: "auto", height: "100px"},
            object: {width: "213px", height: "160px"},
        },
        layoutTemplates: {
            actions: '<div class="file-actions">'n' +
                '    <div class="file-footer-buttons">'n' +
                '        {delete}' +
                '    </div>'n' +
                '</div>',
        }
    }).on("filebatchselected", function(event, files) {
    });
});

希望这会有所帮助:

首先更改变量声明位置,这是初始阶段声明的正确方法。

$(document).on('ready', function() {
    var check_nums = $(".check_nums").val();
    $('#file-th').fileinput({
        showUploadedThumbs: false,
        language: 'th',
        uploadAsync: false,
        maxFileCount: check_nums, 
        resizePreference: 'height',
        resizeImage: true,
        overwriteInitial: false,
        validateInitialCount: true,
        showUpload: false,    
        allowedFileExtensions: ['jpg', 'png', 'jpeg'],
        previewSettings: {
            image: {width: "auto", height: "100px"},
            object: {width: "213px", height: "160px"},
        },
        layoutTemplates: {
            actions: '<div class="file-actions">'n' +
                '    <div class="file-footer-buttons">'n' +
                '        {delete}' +
                '    </div>'n' +
                '</div>',
        }
    }).on("filebatchselected", function(event, files) {
    });
});

然后将更改事件与输入框绑定,并将该输入值分配为文件输入的最大限制。

$(".check_nums").change(function(){
    $("#file-th").fileinput('maxFileCount',$(this).val());
});