django-crispy-forms / crispy-tailwind

A Tailwind template pack for django-crispy-forms
MIT License
329 stars 56 forks source link

Update select_option.html to make select fields more generic #121

Closed ghost closed 2 years ago

ghost commented 2 years ago

This change will take care that integers can match characters. It will fix an issue with django-filter. I've tested this solution in my development environment. Works fine for django-filter based select fields, as well as for regular django forms.

smithdc1 commented 2 years ago

Hi @gldecurtins

Thanks for the PR.

I think this whole section could do with a rework to simplify the logic in the template.

I'm think we should use the optgroups [1] filter from crispy-forms. I'd then expect that we can use the selected value from Django rather than trying to recalculate it in the template. Here's an example of it being used in the bootstrap4 template pack [2]

It's on my list to come back to this once I've got a the next release of crispy-forms (core) out.

In the meantime lets see what the tests say and see if we can merge this.

[1] https://github.com/django-crispy-forms/django-crispy-forms/blob/3c8ed6d4852727614a3ff48a93fee69227a21f91/crispy_forms/templatetags/crispy_forms_filters.py#L131

[2] https://github.com/django-crispy-forms/django-crispy-forms/blob/main/crispy_forms/templates/bootstrap4/layout/checkboxselectmultiple.html#L10

codecov-commenter commented 2 years ago

Codecov Report

Merging #121 (4f8be81) into main (41d3a96) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head 4f8be81 differs from pull request most recent head 8acaf0a. Consider uploading reports for the commit 8acaf0a to get more accurate results

@@           Coverage Diff           @@
##             main     #121   +/-   ##
=======================================
  Coverage   88.20%   88.20%           
=======================================
  Files          37       37           
  Lines         636      636           
  Branches       34       34           
=======================================
  Hits          561      561           
  Misses         66       66           
  Partials        9        9           
Impacted Files Coverage Δ
...lwind/templates/tailwind/layout/select_option.html 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 41d3a96...8acaf0a. Read the comment docs.