-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Short description of the issue
When using AJAX collapsed file upload fields in a process module they will be initialized with the InitHTML5() method and therefore selected files will be instantly uploaded. The upload will fail because the field is intended to work only for connected pages (and the process module has no page connected).
Expected behavior
The field should work just like a non-ajax file field works: Select a file, do NOT upload the file instantly and wait for the upload until the form is submitted, so the upload can be processed via WireUpload afterwards.
Actual behavior
Selected files are instantly uploaded and fail.
Optional: Screenshots/Links that demonstrate the issue
Please see a screencast and screenshots here: https://processwire.com/talk/topic/21602-solved-help-with-ajax-loaded-inputfieldfile-in-processmodule/
Optional: Suggestion for a possible fix
Add a check on top of InitHTML5 to prevent the HTML5 init:
function InitHTML5($inputfield) {
// early exit when page was already initialized oldschool
// this happens when file upload fields are collapsedYesAjax
if($("body").hasClass("ie-no-drop")) return;
Steps to reproduce the issue
Create a processmodule and see the effect:
public function executeDemo() {
$form = $this->modules->get('InputfieldForm'); /** @var InputfieldForm $form */
$tmpDir = $this->files->tempDir('upload_csv');
$f = $this->modules->get('InputfieldFile');
$f->attr('id+name', 'upload_csv');
$f->extensions = 'csv';
$f->maxFiles = 1;
$f->descriptionRows = 0;
$f->overwrite = true;
$f->label = 'Upload CSV yyy';
$f->icon = 'download';
$f->destinationPath = $tmpDir;
$f->collapsed = Inputfield::collapsedYesAjax;
$form->add($f);
return $form->render();
}