Skip to content

form

pdwidgets.widgets.form

Form binder: named fields, validate / values / commit (no chrome of its own).

Form(on_commit=None, error_label=None)

Register named field widgets and collect/validate their values.

Depends on existing controls (:class:FormRow, :class:TextInput, :class:Switch, …). Optional error_label receives the first error string when :meth:validate fails.

Create a form binder.

Parameters:

Name Type Description Default
on_commit callable | None

Called as on_commit(values) when :meth:commit succeeds.

None
error_label Label | None

Shows the first validation error.

None

add(name, widget, validator=None)

Bind widget under name; optional validator(value) -> err|None.

commit()

Validate then invoke on_commit(values) when valid.

Returns:

Name Type Description
bool bool

True if validation passed (and commit ran).

get(name)

Return the widget registered as name, or None.

validate()

Run validators; return {name: error_str} (empty if ok).

Updates error_label.value with the first error when present.

values()

Return {name: widget.value} for all registered fields.