I know this question has been asked before and there is no satisfactory answer given. I'm using sails.js for developing a website.
I have a form with some text fields along with file upload option (for which I have used JQuery file upload plugin). But if no files are chosen and only the text fields are entered, the submit does not proceed further.
This is my main.js submit function:
$(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'
})
And this is my form:
<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>
How to make the library work with no files chosen? Other option is to make two separate submits, one for text fields and one for files. But it will be very messy and I don't prefer that way. Any guidance will be appreciated.