【问题标题】:Filepond customize dropareaFilepond自定义droparea
【发布时间】:2020-09-29 18:03:29
【问题描述】:

使用 filepond 我需要自定义 filepond droparea,这意味着我需要添加一些带有一些占位符图像的自定义 HTML,以便让用户了解应该上传什么样的图像并允许多次上传。

有没有办法做到这一点?

我尝试使用占位符添加一个绝对定位的容器,但我无法在上传我的自定义元素时覆盖。

这是我在 react 中使用 Filepond 的方式:

...
    return (
      <div className="uploads">
        <div className="uploads__placeholders">{placeholderImages}</div>
        <FilePond
          ref={(ref) => (this.pond = ref)}
          files={this.state.files}
          labelIdle={""}
          allowMultiple={true}
          maxTotalFileSize={10485760}
          acceptedFileTypes={this.props.acceptedFileTypes}
          labelMaxTotalFileSize={"Total file size should be lesser than 10MB."}
          maxFiles={maxFilesAllowed}
          allowProcess={this.props.process ? this.props.process : true}
          imagePreviewHeight={135}
          //imagePreviewTransparencyIndicator={"grid"}
          server={{...}}
          onremovefile={(file) => {...}}
          oninit={(t) => {...}}
          onupdatefiles={(fileItems) => {...}}
        />
      </div>
    );
...

所以我创建了一个自定义包装器,并在 filepond 包装器之上与 css 对齐,但这似乎不是理想的解决方法。

【问题讨论】:

  • 您需要先在这里给我们一些可以使用的东西 - minimal reproducible example 显示您的问题,理想情况下也是您已经尝试过的问题。

标签: javascript html css filepond


【解决方案1】:

关键答案是使用labelIdlebeforeAddFile 选项,它可以让您更改默认模板HTML,并预先删除您想要的任何内容。您应该将它添加到您的 Filepond 初始化中。

我注意到如何删除反应中的内容,但一个 jQuery 示例将是这样的:

FilePond.parse(document.body);
const inputElement = document.querySelector('#file_upload');

FilePond.registerPlugin(FilePondPluginImagePreview);

const pond = FilePond.create(inputElement, {
  allowMultiple: true,
  imagePreviewHeight: 135,
  labelIdle: `
    <div style="width:100%;height:100%;">
    	<p>
        Drag &amp; Drop your files or <span class="filepond--label-action" tabindex="0">Browse</span><br>
        Some samples to give you an idea :
      </p>
    </div>
    <div class="images" id="allImages">
       <div class="images_child">
          <img src="https://live.staticflickr.com/4561/38054606355_26429c884f_b.jpg">
       </div>
       <div class="images_child">
          <img src="https://live.staticflickr.com/4561/38054606355_26429c884f_b.jpg">
       </div>
       <div class="images_child">
          <img src="https://live.staticflickr.com/4561/38054606355_26429c884f_b.jpg">
       </div>
     </div>
  `,
  beforeAddFile (e) {
  	$('#allImages').html('');
  }
});
.filepond--drop-label {
  background-color: #ECF7E9;
  height: auto!important;
}

.images {
  display: inline-block;
  padding: 0 5px;
}

.images_child {
  display: contents;
  padding: 0 5px;
  text-align: center;
}

.filepond--root * {
  height: auto;
  padding: 0 4px;
}

img {
  width: 25%;
  opacity: 0.8;
  filter: grayscale(100%);
  border-radius: 8px;
  cursor: pointer;
}


/* Responsive layout - makes a two column-layout instead of four columns */

@media screen and (max-width: 800px) {
  .column {
    flex: 50%;
    max-width: 50%;
  }
}


/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */

@media screen and (max-width: 600px) {
  .column {
    flex: 100%;
    max-width: 100%;
  }
}
<script src="https://unpkg.com/filepond-plugin-image-preview@4.6.4/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond@4.17.1/dist/filepond.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="https://unpkg.com/filepond@4.17.1/dist/filepond.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://unpkg.com/filepond-plugin-image-preview@4.6.4/dist/filepond-plugin-image-preview.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>

<input type="file" name='file' class='filepond' multiple id='file_upload' />

https://jsfiddle.net/d6e2nh93/

免责声明:

1) 我没有将完整的 CSS 用作您的图像示例,因为我认为没有必要,您可以自己轻松完成。

2) 这不是反应答案,而是指导您正确使用filepond 来实现所需结果的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    相关资源
    最近更新 更多