getFormElement
API / @publicodes/forms / getFormElement
function getFormElement<Name>(engine, dottedName): FormElement
Defined in: formElement.ts:127
Generates a UI form element representation based on a Publicodes rule.
This function analyzes a rule’s metadata and type to determine the most appropriate HTML form control for modifying the rule value.
The output describes a form element in a framework-agnostic way, making it suitable for use in various UI frameworks (React, Vue, Svelte, etc.) or in plain JS to render actual HTML form controls.
Type Parameters
Type Parameter |
---|
Name extends string |
Parameters
Parameter | Type | Description |
---|---|---|
engine | Engine <Name > | The Publicodes engine instance |
dottedName | Name | The dotted name identifier of the rule to convert into a form element |
Returns
A FormElement object describing the UI control properties:
- For boolean rules: checkbox or radio buttons (oui/non)
- For dates: date or month input
- For enumerated values: select dropdown or radio group based on number of options
- For strings: text input or textarea
- For numbers: number input
Throws
- If type information is missing for the rule
- If the rule’s data type is not supported
Example
const element = getFormElement(engine, "employee . salary")
// Returns: { element: "input", type: "number", label: "Salary", ... }