8 – How to upload multiple files in a custom form with Form API

I have a custom form created with Form API. In this form, I have a file field with the type managed_file

$form('fichiers_justificatif') = array(
    '#type' => 'managed_file',
    '#title' => 'justificatifs',
    '#upload_validators' => $validators,
    '#upload_location' => 'private://justificatifs',
    '#multiple' => TRUE,
    '#description' => 'types de fichier autorisés : png gif jpg jpeg pdf doc',

It works well, I can upload a file, get its name and url.

But I don’t know how to have a multiple file upload like the one with see in admin or with the webform module.

Example of webform module which handle multiple files upload :

enter image description here

I’ve tried to add '#multiple' => TRUE, but I have an Ajax error after the 2nd file is submitted.

I’ve tried this module Multi-value form element but still have AJAX issue.

I’ve tried drop zone.js but I’n not satisfied with it since it adds an other interface for file (different from the one in admin). User are confused there is an other interface for files.

What could be the better way to handle this ?