Metadata-Version: 2.4
Name: flask-wtforms-htmx
Version: 0.1.0
Summary: A drop-in FlaskForm that brings wtforms-htmx to Flask-WTF.
Keywords: wtforms,htmx,forms,flask,validation
License-Expression: BSD-3-Clause
License-File: LICENSE.rst
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Dist: flask>=3.0
Requires-Dist: flask-wtf>=1.2
Requires-Dist: wtforms-htmx>=0.1.0
Maintainer: Éloi Rivard
Maintainer-email: Éloi Rivard <eloi@yaal.coop>
Requires-Python: >=3.11
Project-URL: Documentation, https://flask-wtforms-htmx.readthedocs.io/
Project-URL: Changes, https://flask-wtforms-htmx.readthedocs.io/changes/
Project-URL: Source Code, https://github.com/yaal-coop/flask-wtforms-htmx
Project-URL: Issue Tracker, https://github.com/yaal-coop/flask-wtforms-htmx/issues
Description-Content-Type: text/markdown

# flask-wtforms-htmx

A drop-in `FlaskForm` that brings
[wtforms-htmx](https://github.com/yaal-coop/wtforms-htmx) to
[Flask-WTF](https://flask-wtf.readthedocs.io/).

**Status: alpha, work in progress.**

`HtmxFlaskForm` replaces Flask-WTF's `FlaskForm`. The usual
`validate_on_submit()` view answers htmx requests, and a mutation click
without JavaScript does not save the form. CSRF protection and file
uploads work as with Flask-WTF.

## Installation

```sh
pip install flask-wtforms-htmx
```

## Example

```python
from flask import redirect, render_template, url_for
from wtforms import ButtonField, FieldList, StringField, SubmitField
from wtforms_htmx.mutations import list_add

from flask_wtforms_htmx import HtmxFlaskForm


class TagsForm(HtmxFlaskForm):
    tags = FieldList(StringField(), min_entries=1)
    add_tag = ButtonField("+").triggers("tags", list_add)
    save = SubmitField("Save")


@app.route("/tags", methods=["GET", "POST"])
def tags():
    form = TagsForm()
    if form.validate_on_submit():
        save(form.data)
        return redirect(url_for("tags"))

    return render_template("tags.html", form=form)
```

With htmx, a click on `+` adds a row without reloading the page. Without
JavaScript, it reloads the page with the new row, and the form is not
saved.

## Links

- Documentation: <https://flask-wtforms-htmx.readthedocs.io/>
- Source: <https://github.com/yaal-coop/flask-wtforms-htmx>
- Issues: <https://github.com/yaal-coop/flask-wtforms-htmx/issues>

## License

BSD-3-Clause. See `LICENSE.rst`.
