【问题标题】:Filepond used only as enchancement to input fileFilepond 仅用作输入文件的增强功能
【发布时间】:2021-05-05 19:24:24
【问题描述】:

有没有办法将 Filepond 配置为仅作为输入文件元素的增强功能?现在,我想将它用作我的表单的插件升级,以处理使用 PHP 后端的上传。

当我上传文件时,输入元素会短暂填充文件数据,然后将其删除,这会破坏我的表单验证和标准上传方法。有没有办法绕过它,或者我应该将我的上传和验证更改为与 Filepond 一起工作?

【问题讨论】:

    标签: javascript file-upload filepond


    【解决方案1】:

    我找到了答案,而且非常简单。

    我使用FilePond:addfile 事件,获取上传的文件并使用DataTransfer API 将其直接传递到输入中。

    const pond = document.querySelector('.filepond--root');
    
    pond.addEventListener('FilePond:addfile', e => {
    
        const dt = new DataTransfer();
        dt.items.add(e.detail.file.file);
    
        let fi = e.target.querySelector('input');
        fi.files = dt.files;
    });
    
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2013-03-31
    • 2020-09-27
    • 1970-01-01
    • 2023-03-31
    • 2010-11-19
    • 1970-01-01
    相关资源
    最近更新 更多