Forms

This section provides some worked examples of different form layouts. Refer to the form reference for a complete description of the available features.

Basic form

Basic form

Source

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<form action="/todoAdd" header="Todo form" skip-confirmation method="post">
    <section name="description" required>
        <header>DESCRIPTION</header>
        <p>Provide a description for the task</p>
        <input type="text" />
        <footer>Reply with description or BACK</footer>
    </section>
    <section name="dueDate" required>
        <header>DUE DATE</header>
        <p>Provide a due date</p>
        <input type="date" />
        <footer>Reply with due date</footer>
    </section>
</form>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { Response, Form, FormItem } = require('onemsdk');

const form = new Form({
    header: 'Todo form',
    meta: { skip_confirmation: true },
    method: 'POST',
    path: '/todoAdd',
    body: [
        new FormItem({
            type: 'string',
            name: 'description',
            header: 'DESCRIPTION',
            description: 'Provide a description for the task',
            required: true,
            footer: 'Reply with description or BACK'
        }),
        new FormItem({
            type: 'date', 
            name: 'dueDate', 
            header: 'DUE DATE', 
            description: 'Provide a due date', 
            required: true, 
            footer: 'Reply with due date'
        }),
    ]
});
const response = new Response(form).toJSON()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import onemsdk
from onemsdk.schema.v1 import (
    Form, FormItem, FormItemType, FormMeta
)

form = Form(
    header='Todo form',
    path='/todoAdd',
    meta=FormMeta(skip_confirmation=True),
    method='POST',
    body = [
        FormItem(
            type=FormItemType.string,
            required=True,
            name='description',
            description='Please provide a description for the task',
            header='DESCRIPTION',
            footer='Reply with description or BACK',
        ),
        FormItem(
            type=FormItemType.date,
            required=True,
            name='due_date',
            description='Provide a due date',
            header='DUE DATE',
            footer='Reply with due date',
        ),
    ]
)

Results