Function showForm

  • Shows a form with the provided schema and resolves to the content of the form.

    Type Parameters

    • T

    Parameters

    Returns Promise<FormResult<T>>

    The form result.

    Example

    interface myInterface {
    myField: string;
    myNumber: string;
    hiddenField: string;
    disabledField: string;
    }

    const result = await showForm<myInterface>(ctx, {
    title: 'Title of the step',
    description: 'Description of the step',
    text: 'Message for the user',
    initialData: {
    myField: 'Initial value',
    },
    fields: [
    {
    type: 'group',
    fields: [
    {
    name: 'myField',
    type: 'text',
    label: 'Field label',
    validation: [{type: 'required', message: 'This field is required'}],
    },
    {
    name: 'myNumber',
    type: 'number',
    label: 'My number',
    validation: [
    {type: 'integer', message: 'Has to be integer'},
    {type: 'moreThan', moreThan: 1, message: 'Has to be more than 1'},
    {
    type: 'custom',
    fn: (value: number) => value >= 3,
    message: 'Has to be more then 3 custom',
    },
    {
    type: 'custom',
    fn: (value: number) => value < 15,
    message: 'Has to be lower then 15',
    },
    ],
    },
    {
    name: 'hiddenField',
    type: 'text',
    label: 'This field is hidden until myField has a value',
    hidden: async (data) => !data.myField,
    },
    {
    name: 'disabledField',
    type: 'text',
    label: 'This field is disabled until myNumber is valid',
    disabled: async (data) =>
    !(data.myNumber && data.myNumber < 15 && data.myNumber >= 3),
    },
    ],
    },
    ],
    buttons: [{value: 'ok', text: 'Submit'}],
    });

Generated using TypeDoc