Manual · API

# `forms`

Windows in general — the plural is the group, the singular (`form`) is the window you are standing in.

Every command on this page carries a worked example.

###
open function

`forms.open("Name", record, options)`

Opens a form, optionally bound to a record. A modal form waits and answers what `form.close(result)` handed back.

With `{ modal: true }` a small form becomes a question: it waits, and `form.close(answer)` over there is the reply here. Check `isOpen` first if a second copy would be wrong.
Worked example

    // Open the invoice window for the list's chosen record.
    const invoice = form.list.value;
    if (invoice) {
        forms.open("InvoiceSheet", invoice);
    }
    // Modal: ask a small form for an answer.
    const answer = forms.open("AskDiscount", null, { modal: true });
    if (answer !== null) {
        form.record.discount = answer;
    }

###
window function

`forms.window("Name")`

Reaches into another open window — the same object `form` is, or `null`. The newest when several are open. This is how a menu script, which has no `form`, still gets its answer onto a window.

Follow it with `forms.bringToFront` — filling a window somebody cannot see is only half a favour.
Worked example

    // A menu script has no `form` — reach into the open list instead.
    const list = forms.window("CustomerList");
    if (list === null) {
        forms.open("CustomerList");
    } else {
        list.list.show(database.customers.where("isActive", "=", true));
        forms.bringToFront("CustomerList");
    }

###
isOpen function

`forms.isOpen("Name")`

Whether that window is up.

Worked example

    if (!forms.isOpen("Dashboard")) {
        forms.open("Dashboard");
    }

###
bringToFront function

`forms.bringToFront("Name")`

Brings it forward — and a window coming forward re-reads what it shows if anything was written meanwhile.

Worked example

    // Fill it, then show it — the other way round is half a favour.
    forms.window("CustomerList").list.show(found);
    forms.bringToFront("CustomerList");

###
close function

`forms.close("Name")`

Closes another window by name. Your own closes with `form.close()`.

Worked example

    // Sign-out closes the workspace windows, then shows the login again.
    forms.close("Dashboard");
    forms.open("Login");

###
names function

`forms.names()`

Every form of the project, as an array of names.

Worked example

    log(forms.names());   // ["Dashboard", "CustomerList", "InvoiceSheet", …]

###
openNames function

`forms.openNames()`

The windows that are open right now.

Worked example

    // Close every window except this one:
    for (const name of forms.openNames()) {
        if (name !== "Dashboard") { forms.close(name); }
    }