Inputs (UI Elements)¶
This page documents the supported ui_element values and their expected options.
Where you set these:
- Preferred:
pydantic_schemaforms.Field(..., ui_element="...") - Or directly via
json_schema_extra={"ui_element": "..."}
from pydantic_schemaforms import Field, FormModel
class Example(FormModel):
email: str = Field(..., ui_element="email")
Supported ui_element values¶
These map to concrete input components in pydantic_schemaforms.inputs.*.
Text¶
text(default)passwordemailsearchtextareaurltel
Notes:
- Long string fields may auto-infer to
textarea. passwordpreserves the value if you supply one (use with care).
Numbers¶
numberrange
Selection¶
selectmultiselectcheckboxradiotoggle(aliases:toggle_switch,checkbox_toggle)combobox
Options for selection widgets:
- Provide choices via
ui_options={"options": [...]}orui_options={"choices": [...]}. - Or use JSON Schema enums (e.g.
Literal[...]/Enum) and the renderer will infer options.
Example:
class Preferences(FormModel):
favorite_color: str = Field(
...,
ui_element="select",
ui_options={
"options": [
{"value": "red", "label": "Red"},
{"value": "blue", "label": "Blue"},
]
},
)
Date/time¶
datetimedatetime(alias:datetime-local)monthweek
Specialized¶
filecolorhiddenssn(alias:social_security_number)phone(alias:phone_number)credit_card(aliases:card,cc_number)currency(alias:money)
These specialized elements are opt-in and will not override normal text fields.
Use them explicitly when you want built-in formatting/pattern behavior.
Pseudo elements¶
These are handled specially by the renderer (not standard inputs):
layout: layout-only schema fields (see docs/layouts.md)model_list: repeatable nested model items
Unknown elements¶
If you set ui_element to an unsupported value, the renderer falls back to a basic text input.
If you need a custom widget:
- Implement a
BaseInputsubclass - Register it at runtime via
pydantic_schemaforms.inputs.registry.register_input_class()
(Then you can use your custom ui_element key in schemas.)