formio / react

JSON powered forms for React.js

Home Page:https://form.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing submission data object, doesn't pre-fill the file fields (or Giving e.files.forEach is not a function)

fless-lab opened this issue · comments

Here is my code :

<Form form={validationForm.form} submission={{ data: task.data ?? prefilledData ?? validationForm.formdata, }} onSubmit={submitHandler} options={{ readOnly: isTaskCompleted || disabled, noAlerts: true }} formReady={handleFormReady} />

  the submission data is the following : 
  
  `{
"nomDuDemandeur": "json",
"ficheDapprobation": {
    "type": "file",
    "value": [
        {
            "storage": "url",
            "name": "ok-2af7f28e-c4d0-458a-9e47-2f2ee6242995.pdf",
            "url": "http://my.server.url/documents?id=10nbl001yw51d&storage=files",
            "size": 3848503,
            "type": "application/pdf",
            "data": [
                {
                    "id": "10nbl001yw51d",
                    "filename": "ok.pdf",
                    "size": 3848503,
                    "type": "application/pdf",
                    "ext": "pdf",
                    "url": "/documents/10nbl001yw51d.pdf",
                    "fileStorage": "files"
                }
            ],
            "originalName": "ok.pdf",
            "hash": "c75173910a2bd811bd3d81e6b2596d12"
        }
    ]
},
"dossierValide": "oui",
"ageDuDemandeur": 23

}`

Apart from the file component, all the rest are correctly prefilled.

Here is my form component :

{"components": [ { "label": "Nom du demandeur", "tableView": true, "key": "nomDuDemandeur", "type": "textfield", "input": true }, { "label": "Age du demandeur", "mask": false, "tableView": false, "delimiter": false, "requireDecimal": false, "inputFormat": "plain", "truncateMultipleSpaces": false, "key": "ageDuDemandeur", "type": "number", "input": true }, { "label": "Fiche d'approbation", "tableView": false, "storage": "url", "webcam": false, "fileTypes": [ { "label": "", "value": "" } ], "key": "ficheDapprobation", "type": "file", "url": "http://127.0.0.1:8089/processing/api/v1/xflow", "input": true }, { "label": "Dossier valide ?", "optionsLabelPosition": "right", "inline": true, "tableView": false, "values": [ { "label": "Oui", "value": "oui", "shortcut": "" }, { "label": "Non", "value": "non", "shortcut": "" } ], "validate": { "required": true }, "key": "dossierValide", "type": "radio", "input": true } ] }

Here is the preview :

scrnli_03_05_2023 08-56-35
scrnli_03_05_2023 08-57-19

@fless-lab value of the File component should be an array of objects.
Like that:

"ficheDapprobation": [
        {
            "storage": "url",
            "name": "ok-2af7f28e-c4d0-458a-9e47-2f2ee6242995.pdf",
            "url": "http://my.server.url/documents?id=10nbl001yw51d&storage=files",
            "size": 3848503,
            "type": "application/pdf",
            "data": [
                {
                    "id": "10nbl001yw51d",
                    "filename": "ok.pdf",
                    "size": 3848503,
                    "type": "application/pdf",
                    "ext": "pdf",
                    "url": "/documents/10nbl001yw51d.pdf",
                    "fileStorage": "files"
                }
            ],
            "originalName": "ok.pdf",
            "hash": "c75173910a2bd811bd3d81e6b2596d12"
        }
    ]