## AirForm 0.2.0: Define a model, get a form

AirForm turns Pydantic models into validated, rendered HTML forms. Define your data with AirField metadata, and AirForm handles the rest: labels, placeholders, help text, dropdowns, textareas, checkboxes, error messages, and accessibility attributes. Works standalone with any ASGI framework or as part of Air.

```sh
uv add AirForm
```

### What's new

- **Validate and render from the same object.** `AirForm[MyModel]` gives you `validate()` to check form data and `render()` to produce HTML, all in one class. Type-safe: after validation, `form.data` is typed as your model.

- **Full AirField metadata vocabulary.** The renderer reads every AirField presentation type: Label for display names, Placeholder for hint text, HelpText for explanatory text below inputs, Choices for `<select>` dropdowns, Widget for textarea/email/url/password, Autofocus for initial focus. PrimaryKey and Hidden("form") fields are automatically skipped.

- **Accessible HTML by default.** Rendered fields include `aria-invalid`, `aria-describedby` linking inputs to their error messages, and `role="alert"` on errors. Checkbox labels render after the input. Help text gets its own `aria-describedby` link.

- **Pydantic constraints become HTML5 validation.** `min_length`, `max_length`, `ge`, `le`, and `pattern` on your model fields produce `minlength`, `maxlength`, `min`, `max`, and `pattern` attributes on the HTML inputs. Works with `AirField()`, `pydantic.Field()`, and `Annotated[str, MinLen(2)]`.

- **Swappable widget.** Daniel's original design pattern: `AirForm.widget` is a `staticmethod` class attribute. Override it on your subclass to replace the entire renderer with your own callable.

- **`from_request()` for ASGI handlers.** Async classmethod that reads `request.form()`, validates, and returns a populated form. Works with FastAPI's `Depends` for dependency injection.

- **User-friendly error messages.** Pydantic's technical error types (`missing`, `int_parsing`, `string_too_short`) are translated to plain language ("This field is required.", "Please enter a valid number.", "This value is too short.").

- **CLI preview.** `airform preview myapp.models:ContactModel` renders any Pydantic model's form HTML to the terminal with syntax highlighting.

### Contributors

[@audreyfeldroy](https://github.com/audreyfeldroy) (Audrey M. Roy Greenfeld) designed and built this release.

This work is built on [@pydanny](https://github.com/pydanny)'s (Daniel Roy Greenfeld) original [form rendering design](https://github.com/feldroy/air/commit/de07dbf) in Air. Daniel created the swappable widget pattern, the render() method, and the pydantic-type-to-HTML-type mapping that AirForm extends. His instinct to keep the renderer separate and replaceable is what made this package possible.
