javascriptreactjsredux-formadmin-on-rest

Get form data in handleSubmit


Can anyone help me?

In the Admin-on-rest framework, I want to write a handleSubmit in SimpleForm. How to get form data in handleSubmit.

I have two file input: FileInput and ImageInput and one TextInput. I want to send files and text to the server after submitting the form. The input files use the react-dropzone and don't send the files to the server after submitting.

I can not find any example for this.

let filex;    
<SimpleForm handleSubmit={(data)=>{ console.log(data); }}>
         <TextInput label="عنوان کتاب" source="title" validate={required} />
            <RichTextInput label="توضیحات" source="description" toolbar={[ 
                ['bold', 'italic', 'underline', 'link'],
                [{ 'direction': 'rtl' }],
                [{ 'align': [] }],
                ['clean'],
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
            ]} validate={required} />
            <ImageInput source="bookImg" 
            label="تصویر کتاب" 
            input={{
                value: filex,
                onChange: (file) => {
                    filex = file;
                }
            }}
            validate={required} accept="image/*">
                <ImageField source="src" title="title" />
            </ImageInput>
            <FileInput source="bookPdf" label="فایل کتاب" validate={required} accept="application/pdf">
                <FileField source="src" title="title" />
            </FileInput>
    </SimpleForm>

Solution

  • This is covered in the documentation:

    End of the FileInput section: https://marmelab.com/admin-on-rest/Inputs.html#fileinput

    And on the restClient: https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload