ui.modelform
ModelForm
Create a form from a pydantic model. The form will be rendered with the fields from the model.
The model can also be a pydantic model instance. The form will be prefilled with the instance data.
Example:
from pydantic import BaseModel
from uiwiz import ui
class DataInput(BaseModel):
name: str
age: int
@app.ui("/handle-submit")
async def handle_submit(data: DataInput):
ui.toast(f"Name: {data.name}, Age: {data.age}").success()
ui.modelForm(DataInput).on_submit(handle_submit)
Constructor
model: BaseModelNo default required argument
compact: bool= True
card_classes: str= border border-base-content rounded-lg shadow-lg w-full
label_classes: str= flex-auto w-52
size: Literal= md
Methods
after_render(html: str) -> str
This method is called after the element is rendered.
:param html: The rendered HTML of the element.
before_render() -> Any
This method is called before the element is rendered.
classes(input: str) -> Self
Set tailwind classes for the element.
:param input: The tailwind classes to apply to the element.
:return: The current instance of the element.
extend_kwargs(kwargs: dict, ele_args: list, key: str, field_arg: str, ele: Element) -> bool
No documentation providedget_classes() -> str
Get html classes of the element.
:return: The classes of the element.
:type: str
get_type_and_uianno(args: Tuple) -> Optional
No documentation providedon_submit(args: Any, kwargs: Any) -> ModelForm
No documentation providedrender(render_script: bool) -> str
Render the element as HTML.
:param render_script: If any element has a javascript script, it will be rendered as well.
:type render_script: bool
render_element(ele: Element, key: str, classes: Optional, field_arg: Optional, kwargs: Any) -> NoneType
No documentation providedrender_element_dropdown(field_class: type, key: str, placeholder: Optional) -> NoneType
No documentation providedrender_element_radio(ele: UiAnno, key: str, field_args: Tuple) -> NoneType
No documentation providedrender_key_override(args: Tuple, key: str, kwargs: Any) -> NoneType
No documentation providedrender_model(kwargs: Any) -> Form
No documentation providedrender_model_attributes(key: Any, field_type: Any, kwargs: Any) -> ModelForm
No documentation providedrender_type_hint_without_args(args: Tuple, annotated: bool, field_type: Any, key: Any) -> Element
No documentation providedrender_with_args_annotated(args: Tuple, annotated: bool, field_type: Tuple, key: str) -> Element
No documentation providedsize(size: Literal) -> Self
Set the size of the element.
:param size: The size of the element.
:return: The current instance of the element.