django-crispy-forms / django-crispy-forms/django-crispy-forms
Render single field including use of helper
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 731
- PR merge metrics
- No merged PRs in 30d
Description
* Package version: 2.1
* Django version: 5.0.1
* Python version: 3.11.9
* Template pack: bootstrap5
### Description:
First off, thank you so much to the maintainers of this project. It makes me so productive when working with forms. You are all amazing.
This is more of a conversation starter than a bug report, although it may turn into a feature request. I completely understand if the answer to this is the request is out of scope.
I have been getting more into using htmx in my project. That has led me to think it would be nice if I could render one field from a form and return that to htmx. I have come across this need in two different scenarios so far. The most recent is to be able to validate a single field when that field is changed in the browser. `as_crispy_field` almost does what I need, the only thing missing is that it doesn't take the helper's layout into account. This means that I am unable to apply the `hx-` attributes added in the layout's Fields when rendering that one field.
I have found a work-around where I locate the field in the layout, extract the attributes, then update the field's widget's attributes before calling `as_crispy_field`. There are probably better, more elegant solutions, but that is what I have come up with after playing with this, putting it down, and then coming back to it again.
I also wonder how something like [django-template-partials](https://pypi.org/project/django-template-partials/) eventually have a part in something like this? Similarly, does [field group](https://docs.djangoproject.com/en/5.1/releases/5.0/#simplified-templates-for-form-field-rendering) come into play? I don't fully understand how these two items could potentially impact a library like crispy-forms.
I hope it is appropriate to post this. If not, I am happy to take the conversation elsewhere, I definitely don't want to burden the maintainers with issues.
Thank you.
Contributor guide
Assessment
This issue has not been assessed yet.