What it does
A compact dropdown for one choice.
This is a visual component. Drag it from Toolbox, or double-click to insert it.
Set it up
- Add ComboBox from Toolbox.
- Set its Name to
samplefor the examples below. Names are case-sensitive. - Configure the component-specific properties below.
- Open the Events inspector to add a handler: methods go in event.js, imports and subscriptions in script.js. Right-click View Events or View Script to edit either file. Use View CSS for scoped styles and View Custom Properties for JSON values.
- Save sources, save the project, and open a fresh Preview. Scripts execute in Preview.
JavaScript example
These examples use supported inline subscriptions for brevity. The Events inspector can generate separate class methods in event.js instead.
Items are a string array in JavaScript and one item per line in the inspector. Indices are zero-based; -1 clears the selection. Navigation components raise navigate but do not load pages automatically.
const selection = forma.bind("sample", "selectedIndex");
selection.subscribe(index => {
const items = forma.get("sample", "items");
console.log(index >= 0 ? items[index] : "No selection");
});
Component properties
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Items (one per line) | items | textarea | — | items |
| Selected index | selectedIndex | number | -1–10000 | selectedIndex |
Runtime property API
Use forma.get("sample", key), forma.set("sample", key, value), or forma.bind("sample", key). Read a binding with .value; write only when the Binding column permits it. Numbers and booleans must keep their types. Arrays are passed directly, not as JSON strings.
| Key | Value type | get | set | Binding | Meaning / restrictions |
|---|---|---|---|---|---|
text | string | Yes | Yes | Read/write | Display text; use value to read live text input. |
enabled | boolean | Yes | Yes | Read/write | Enabled |
visible | boolean | Yes | Yes | Read/write | Visible |
tag | string | Yes | Yes | Read/write | Tag |
x | number | Yes | Yes | Read/write | Parent-content X coordinate. Writes are rejected for managed/docked children. |
y | number | Yes | Yes | Read/write | Parent-content Y coordinate. Writes are rejected for managed/docked children. |
width | number | Yes | Yes | Read/write | Configured model width; managed layouts/custom CSS can change rendered size. |
height | number | Yes | Yes | Read/write | Configured model height; managed layouts/custom CSS can change rendered size. |
minimumWidth | number | Yes | Yes | Read/write | Range 0–1600. Invalid types are rejected; numeric values clamp. |
minimumHeight | number | Yes | Yes | Read/write | Range 0–1200. Invalid types are rejected; numeric values clamp. |
maximumWidth | number | Yes | Yes | Read/write | Range 0–1600. Invalid types are rejected; numeric values clamp. |
maximumHeight | number | Yes | Yes | Read/write | Range 0–1200. Invalid types are rejected; numeric values clamp. |
backColor | string | Yes | Yes | Read/write | Background |
foreColor | string | Yes | Yes | Read/write | Foreground |
borderStyle | "none" | "solid" | "dashed" | "dotted" | Yes | Yes | Read/write | Border style |
borderColor | string | Yes | Yes | Read/write | Border color |
borderWidth | number | Yes | Yes | Read/write | Range 0–10. Invalid types are rejected; numeric values clamp. |
borderSides | "all" | "none" | "top" | "bottom" | "left" | "right" | "top,bottom" | "left,right" | "top,left,right" | "bottom,left,right" | Yes | Yes | Read/write | Border sides |
borderRadius | number | Yes | Yes | Read/write | Range 0–100. Invalid types are rejected; numeric values clamp. |
opacity | number | Yes | Yes | Read/write | Range 10–100. Invalid types are rejected; numeric values clamp. |
shadow | "None" | "Small" | "Medium" | "Large" | Yes | Yes | Read/write | Shadow |
cursor | "default" | "pointer" | "text" | "crosshair" | "help" | "not-allowed" | Yes | Yes | Read/write | Cursor |
fontFamily | "Segoe UI" | "Arial" | "Consolas" | "Georgia" | Yes | Yes | Read/write | Font family |
fontSize | number | Yes | Yes | Read/write | Range 8–48. Invalid types are rejected; numeric values clamp. |
fontWeight | "normal" | "bold" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | Yes | Yes | Read/write | Weight |
fontStyle | "normal" | "italic" | Yes | Yes | Read/write | Font style |
textAlign | "left" | "center" | "right" | Yes | Yes | Read/write | Alignment |
lineHeight | number | Yes | Yes | Read/write | Range 0.5–4. Invalid types are rejected; numeric values clamp. |
letterSpacing | number | Yes | Yes | Read/write | Range -5–20. Invalid types are rejected; numeric values clamp. |
marginTop | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
marginRight | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
marginBottom | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
marginLeft | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
paddingTop | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
paddingRight | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
paddingBottom | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
paddingLeft | number | Yes | Yes | Read/write | Range 0–64. Invalid types are rejected; numeric values clamp. |
focusable | boolean | Yes | Yes | Read/write | Focusable |
tabIndex | number | Yes | Yes | Read/write | Range 0–32767. Invalid types are rejected; numeric values clamp. |
toolTip | string | Yes | Yes | Read/write | Tooltip |
cssClass | string | Yes | Yes | Read/write | CSS class |
layoutSlot | number | Yes | Yes | Read/write | One-based parent pane, page, or table cell. |
dock | "none" | "top" | "bottom" | "left" | "right" | "fill" | Yes | Yes | Read/write | Parent-managed edge/fill layout. Takes priority over Anchor. |
anchor | "none" | "top,left" | "top,right" | "bottom,left" | "bottom,right" | "top,left,right" | "bottom,left,right" | "top,bottom,left" | "top,bottom,right" | "top,bottom,left,right" | "top" | "bottom" | "left" | "right" | "top,bottom" | "left,right" | Yes | Yes | Read/write | Comma-separated edges; opposite edges stretch. Use exact option strings. |
selectedIndex | number | Yes | Yes | Read/write | Zero-based; -1 clears selection. |
items | string[] | Yes | Yes | Read/write | String array; inspector uses one item per line. |
Set commands cross the native bridge asynchronously. An immediate get after set may return the previous value. Observe a binding or use the assigned value locally. Getter arrays are copies. Geometry is configured model geometry; layout and CSS may override rendered bounds.
Shared inspector fields
| Field | Inspector key | Editor | Accepted values / range | Runtime key |
|---|---|---|---|---|
| Name | name | text | — | Designer only |
| ID (read-only) | id | text | — | Designer only |
| Text / Title | text | text | — | text |
| Tag | tag | text | — | tag |
| Locked | locked | checkbox | — | Designer only |
| Background | backColor | color | — | backColor |
| Foreground | foreColor | color | — | foreColor |
| Border style | borderStyle | select | none, solid, dashed, dotted | borderStyle |
| Border color | borderColor | color | — | borderColor |
| Border width | borderWidth | number | 0–10 | borderWidth |
| Border sides | borderSides | select | all, none, top, bottom, left, right, top,bottom, left,right, top,left,right, bottom,left,right | borderSides |
| Radius | borderRadius | number | 0–100 | borderRadius |
| Opacity (%) | opacity | number | 10–100 | opacity |
| Shadow | shadow | select | None, Small, Medium, Large | shadow |
| Cursor | cursor | select | default, pointer, text, crosshair, help, not-allowed | cursor |
| Font family | fontFamily | select | Segoe UI, Arial, Consolas, Georgia | fontFamily |
| Font size | fontSize | number | 8–48 | fontSize |
| Weight | fontWeight | select | normal, bold, 100, 200, 300, 400, 500, 600, 700, 800, 900 | fontWeight |
| Font style | fontStyle | select | normal, italic | fontStyle |
| Alignment | textAlign | select | left, center, right | textAlign |
| Line height | lineHeight | number | 0.5–4 | lineHeight |
| Letter spacing | letterSpacing | number | -5–20 | letterSpacing |
| X | x | number | 0–1600 | x |
| Y | y | number | 0–1200 | y |
| Width | width | number | 24–1600 | width |
| Height | height | number | 20–1200 | height |
| Min width | minimumWidth | number | 0–1600 | minimumWidth |
| Min height | minimumHeight | number | 0–1200 | minimumHeight |
| Max width (0=auto) | maximumWidth | number | 0–1600 | maximumWidth |
| Max height (0=auto) | maximumHeight | number | 0–1200 | maximumHeight |
| Margin top | marginTop | number | 0–64 | marginTop |
| Margin right | marginRight | number | 0–64 | marginRight |
| Margin bottom | marginBottom | number | 0–64 | marginBottom |
| Margin left | marginLeft | number | 0–64 | marginLeft |
| Padding top | paddingTop | number | 0–64 | paddingTop |
| Padding right | paddingRight | number | 0–64 | paddingRight |
| Padding bottom | paddingBottom | number | 0–64 | paddingBottom |
| Padding left | paddingLeft | number | 0–64 | paddingLeft |
| Enabled | enabled | checkbox | — | enabled |
| Visible | visible | checkbox | — | visible |
| Focusable | focusable | checkbox | — | focusable |
| Tab index | tabIndex | number | 0–32767 | tabIndex |
| Tooltip | toolTip | text | — | toolTip |
| CSS class | cssClass | text | — | cssClass |
| Pane / tab / cell | layoutSlot | number | 1–100 | layoutSlot |
| Dock | dock | select | none, top, bottom, left, right, fill | dock |
| Anchor | anchor | select | none, top,left, top,right, bottom,left, bottom,right, top,left,right, bottom,left,right, top,bottom,left, top,bottom,right, top,bottom,left,right, top, bottom, left, right, top,bottom, left,right | anchor |
Events and lifecycle
Component hooks: Relevant DOM events and shared lifecycle events.
Only applicable browser events fire: a control without text input will not produce native input events just because a handler is registered. Event names are case-insensitive. Put handlers on the component producing the event; a Timer Tick handler belongs to the Timer, or can be observed through forma.root.on("Tick", handler). See the event guide for payloads, validation, cleanup, and startup order.
Property-change payload
All components can report PropertyChanged for changed projected runtime properties. Handlers expose source/subscriber component handles; native DOM targets remain available. Input/Change can supply typed property values, while Click normally supplies identity without a property/value pair.
forma.on("PropertyChanged", ({ source, property, value, previousValue, origin }) => {
console.log(source.name, property, previousValue, "→", value, origin);
});
Use forma.root.on(...) to observe the active form, and event.toJSON() for portable logs. Subscriptions return unsubscribe and are cleaned up with the subscribing script.
C# example
Use this in a configured Forma C# host, not in script.js. The renderer is your host's WebView2Renderer instance.
var sample = new Forma.Core.Controls.ComboBox
{
Name = "sample"
};
await renderer.RenderAsync(sample);
C# model reference
These are Core constructor defaults, not necessarily the Builder’s drop-time styles or size. Appearance fields belong to Builder Appearance. C# events are not all forwarded to JavaScript.
| Property | C# type | Constructor default | Writable |
|---|---|---|---|
Items | String[] | ["Item 1","Item 2","Item 3"] | Yes |
SelectedIndex | Int32 | 0 | Yes |
Name | String | null | Yes |
LayoutSlot | Int32 | 1 | Yes |
X | Nullable1` | null | Yes |
Y | Nullable1` | null | Yes |
Text | String | null | Yes |
Value | String | null | Yes |
Placeholder | String | null | Yes |
Label | String | null | Yes |
ControlType | String | "combobox" | No |
Core methods: GetRenderState(), HandleRuntimeEvent(runtimeEvent), Add(child), Insert(index, child), MoveChild(child, index), Remove(child).
Core events: SelectedIndexChanged, ChildAdded, ChildRemoved, PropertyChanged.