Skip to content

Build a form without mutation

Charly POLY edited this page Jun 6, 2018 · 3 revisions

Build a form without mutation is slightly different. You have to pass a ApolloFormConfigManual:

interface ApolloFormConfigManual extends ApolloFormConfigBase {
    schema: JSONSchema6;
    saveData: (formData: any) => any;
}

I really advise you to use the functional-json-schema package to build a JSON Schema object "by hand".

Example:

import { schema, types } from 'functional-json-schema';
// imports ... 

const form = p => (
    <ApplicationForm
        title={'Todo Form'}
        config={{
            name: 'todo',
            schema: schema({
                todo: {
                    name: types.type('string', { required: true }),
                    completed: types.type('boolean')
                }
            }),
            saveData: data => {
                console.log('save !', data);
            }
        }}
        data={{}}
        ui={{}}
    />
);