The select field (type: "select") displays a drop-down list in the modal form() dialog that lets you select one of the available options.
Since version 3.17, the modal form supports a hierarchy of options. The syntax is compatible with the Scheduler component resources property.
The options array items have the following structure:
import {Modal} from "@daypilot/modal";
// ...
async function select() {
const resources = [
{ name: "Resource A", id: "A" },
{ name: "Resource B", id: "B" },
{ name: "Resource C", id: "C" },
];
const form = [
{
name: "Resource",
id: "resource",
options: resources,
type: "select",
},
];
const data = {
resource: "B",
};
const modal = await Modal.form(form, data);
console.log(modal.result);
}
Example that uses a hierarchy of options:
import {Modal} from "@daypilot/modal";
// ...
async function selectHierarchy() {
const form = [
{
name: "Resource",
id: "resource",
type: "select",
disableParents: true,
options: [
{
name: "Resource Alpha", id: "resource-alpha", children: [
{name: "Child 1", id: "child1"},
{name: "Child 2", id: "child2"},
]
},
{
name: "Resource Beta", id: "resource-beta", children: [
{name: "Child 3", id: "child3"},
{name: "Child 4", id: "child4"},
]
},
]
},
];
const data = {
tree: "child2"
};
const modal = await Modal.form(form, data);
console.log(modal);
};