Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert underscore to hyphens in generic attributes names #524

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

yakky
Copy link

@yakky yakky commented Jul 20, 2023

Just a draft idea to address #267 to see if there is any interesting in solving the issue

The change replace _ to - in generic tag attributes

So i can do something like {% bootstrap_button data_bs_toggle="collapse" data_bs_target="#update-group-9" button_type="reset" content="Cancel" %}

Generic attributes (like data_bs_toggle) are passed to render_tag without any changes while templatetag arguments (like button_type) are not, so it's safe to make this change without interfering django-bootstrap5 behaviour

@apapsch
Copy link

apapsch commented Apr 16, 2024

Just a draft idea to address #267 to see if there is any interesting in solving the issue

Yes, please merge these changes.

@yakky
Copy link
Author

yakky commented Apr 27, 2024

@dyve is this something you'd be interested to merge? If so I will complete this with tests to make it actually mergeable

@dyve
Copy link
Member

dyve commented Apr 27, 2024

The idea of converting data_ tot data- is interesting. For anything not starting with data_, it becomes a possible risk I think.

@yakky
Copy link
Author

yakky commented Apr 27, 2024

the idea behind this PR is to allow integrating htmx attributes (hx-*) which is currently not possible to support

@dyve
Copy link
Member

dyve commented Apr 27, 2024

Ok, Let's see it.

@yakky
Copy link
Author

yakky commented Apr 27, 2024

@dyve this is a first draft. I included tests to check that no existing attribute is altered

@yakky yakky marked this pull request as ready for review July 6, 2024 12:07
@Fingel
Copy link

Fingel commented Oct 27, 2024

Came here to open an issue about this. Being able to add arbitrary attributes is almost a necessity these days, and it in the template seems less hacky than setting it on the python side.

Although this only seems to work for buttons, it would be great if we could pass through extra attributes for fields as well.

@don-philipe
Copy link

I'm interested in this solution as well. Right now I use a custom template tag and overwrite the django_bootstrap5 render_tag() function with the code changes from this PR. It works, but I would appreciate a native solution.

@francoisfreitag
Copy link
Contributor

This looks pretty useful! With the data_ prefix, it should be mostly safe.

A possible addition is to support custom prefixes through a setting. That offers options to:

  1. (default) BOOTSTRAP5["hyphen-attributes-prefixes"] = ["data"], converts all data_* to data-*
  2. BOOTSTRAP5["hyphen-attributes-prefixes"] = ["data", "hx"], same as 1., and converts hx_* to hx-*
  3. BOOTSTRAP5["hyphen-attributes-prefixes"] = [] No conversion.

It should be straightforward to maintain, and leaves an option for users wanting custom prefixes.

@francoisfreitag
Copy link
Contributor

francoisfreitag commented Dec 16, 2024

#524 (comment)

I’ll try to push an update for this in the coming weeks.

@dyve
Copy link
Member

dyve commented Dec 16, 2024

I'm actually trying to figure it out right now, watch this space.

@dyve
Copy link
Member

dyve commented Dec 16, 2024

See #737

@dyve
Copy link
Member

dyve commented Dec 16, 2024

@yakky I continued this (with a parameter added) in #737. I'll make sure you get the credits if we merge this. If there is a better way on GitHub to continue work on a branch in someone else's repo, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants