Skip to main content

sdk.form.showform

Home > @matterway/sdk > Form > showForm

Form.showForm() function

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

Signature:

export declare function showForm<T>(ctx: Context, options: ShowFormOptions): Promise<FormResult<T>>;

Parameters

ParameterTypeDescription
ctxContextContext object.
optionsShowFormOptions

Returns:

Promise<FormResult<T>>

The form result.

Example

  interface myInterface {
myField: string;
myNumber: 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'
},
],
},
]},
],
buttons: [
{value: 'ok', text: 'Submit'},
],
});