【问题标题】:BlueImp jQuery FIle Upload - Adding customizable name field for each fileBlueImp jQuery 文件上传 - 为每个文件添加可自定义的名称字段
【发布时间】:2014-12-28 19:36:38
【问题描述】:

我在 blueimpe jquery 中添加名称字段多个文件上传时遇到问题。

它始终采用名称文本字段的最后分配值。如何解决这个问题?

<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
  {% for (var i=0, file; file=o.files[i]; i++) { %}
  <tr class="template-upload">
    <td class="preview"><span class="fade"></span></td>
    <td class="name"><span>{%=file.name%}</span></td>

    <td class="image_name"><span><input type="text" name="image[name]"value="{%= file.name.split('/').pop().split('.').shift()%}" required/></span></td>
    <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
    {% if (file.error) { %}
    <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
    {% } else if (o.files.valid && !i) { %}
    <td>

    </td>
    <td class="start">{% if (!o.options.autoUpload) { %}
      <button>

        <span>{%="Upload"%}</span>
      </button>
      {% } %}</td>
    {% } else { %}
    <td colspan="2"></td>
    {% } %}
    <td class="cancel">{% if (!i) { %}
      <button >

        <span>{%="Remove"%}</span>
      </button>
      {% } %}</td>
  </tr>
  {% } %}
</script>

各种方法我都试过了。

【问题讨论】:

    标签: jquery ruby-on-rails paperclip blueimp


    【解决方案1】:

    在提交回调中添加这个

    $('#fileupload').bind('fileuploadsubmit', function (e, data) {
        var inputs = data.context.find(':input');
        if (inputs.filter('[required][value=""]').first().focus().length) {
            return false;
        }
        data.formData = inputs.serializeArray();
     });

    .first() 将采用第一个输入值。

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2020-10-28
      • 2014-10-07
      • 1970-01-01
      • 2017-06-12
      相关资源
      最近更新 更多