{% hput %}
Concept
hput
customizes a BoundField for rendering, with option to supply inline validation using the logic derived from hernantz.
Use of django_widget_tweaks inlined with {% hput ... %}
works:
hx_enable_inline_validation()
Requires htmx-compatible view
Need to handle the request, checking if it is an htmx request (see is_htmx()) and then render the template with the form.
Given a BoundField
and a url
, implement inline field validation proposed by
hernantz.
It makes use of various tags from htmx.
The gist: form is prematurely submitted (because of hx-post
) as an AJAX-request,
the partial template response will hx-swap
an hx-target
. In other words, the
old field is replaced by the same field... but now as a result of form.is_valid()
.
The response, if it contains errors, will include an error list for the field.
Instead of rendering the entire partial response, the use of hx-select
limits the
replacement to a segment of the partial response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bound |
BoundField
|
A Django field with data previously submitted |
required |
url |
str
|
Where the form is submitted. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string of text attributes that can be added to a wrapping div of a |