我正在尝试将dropzone.js与其他表单元素结合使用,除了一件事,一切都正常。我有一些其他表单元素的验证规则,当其中一个验证规则失败时,它会发送带有ajax响应的错误。发生错误时,所有dropzone文件都会从队列中取消。然后我需要再次手动添加删除的文件并提交表单。即使发生错误,有没有办法将所有图像文件保留在队列中,以便我可以尝试重新发送它们?
这是我的dropzone配置:
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 5,
addRemoveLinks:true,
这是在表单提交后调用的方法:
public function save($request)
{
$request = $request->all();
// Create a new validator instance from our validation rules
$validator = Validator::make($request, $this->validationRules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
$this->errors = $validator->errors();
return false;
}
$user_id = getLoggedInId();
$request['operator_id'] = $this->operator->getId($user_id);
$result = $this->visit->add($request);
if ($result == 'updated')
{
$this->success = 'Successfully Updated!';
return $result;
}
elseif ($result == 'failed')
{
$this->errors = 'failed!';
return false;
}
elseif ($result == 'notAllowed')
{
$this->errors = 'Not Allowed to update this record';
return false;
}
else
{
if (Input::file('file'))
{
$visit_id = $result->id;
$files = Input::file('file');
$today = Carbon::now();
$patient_id = Input::get('patient_uid'); //need more validation later on
$center_id = substr($patient_id, 0, 3);
$uid = substr($patient_id, -5);
$upload_dir = $center_id . '/' . $today->year . '/' . $today->month . '/';
foreach ($files as $file)
{
// public/uploads
$response = $this->report->upload($file, $upload_dir, $visit_id, $uid);
if ($response['error'])
{
$this->errors = $response['message'];
return false;
}
}
}
$this->success = trans('patients/visit_form.successfully_created');
return $result;
}
这是提交表单的逻辑:
this.element.querySelector("input[type=submit]").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
if (myDropzone.getQueuedFiles().length > 0)
{
myDropzone.processQueue();
} else {
submitVisitForm();
}
});