我知道以前有人问过这个问题,但没有给出令人满意的答案。我正在使用sails.js 开发网站。
我有一个带有一些文本字段的表单以及文件上传选项(为此我使用了 JQuery 文件上传插件)。但是,如果没有选择文件并且只输入文本字段,则提交不会继续进行。
这是我的 main.js 提交函数:
$(function () {
'use strict';
var propertyId = document.getElementById("helper").getAttribute("data-name");
var fileCount = 0, fails = 0, successes = 0;
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
//url: 'server/php/'
singleFileUploads: false,
url: '/admin/property/'+propertyId+'/pictures/upload'
})
这是我的表格:
<form id="fileupload" action="/admin/property/<%=propertyId%>/pictures/upload" method="POST" enctype="multipart/form-data">
<noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript>
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<label>Stage Title:</label>
<input class="form-control" type="text" name="stageTitle"/>
<br>
<label>Start Date:</label>
<input class="form-control" type="text" name="startDate"/>
<br>
<label>End Date:</label>
<input class="form-control" type="text" name="endDate"/>
<br>
<label>Description:</label>
<textarea class="form-control" type="text" name="description"> </textarea>
<br>
<label>Pictures:</label><br>
<span class="btn btn-success fileinput-button">
<span>Add Images...</span>
<input type="file" name="files" id="files" multiple>
</span>
<button type="reset" class="btn btn-warning cancel">
<span>Cancel upload</span>
</button>
<span class="fileupload-process"></span>
</div>
<div class="col-lg-5 fileupload-progress fade">
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<div class="progress-extended"> </div>
</div>
<button type="submit" class="btn btn-primary start">
<span>Save</span>
</div>
<table id="pictureTable" role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
</button>
</form>
如何使库在没有选择文件的情况下工作?另一种选择是进行两个单独的提交,一个用于文本字段,一个用于文件。但这会很混乱,我不喜欢这种方式。任何指导将不胜感激。