django-bootstrap5 icon indicating copy to clipboard operation
django-bootstrap5 copied to clipboard

Convert underscore to hyphens in generic attributes names

Open yakky opened this issue 2 years ago • 6 comments

Just a draft idea to address https://github.com/zostera/django-bootstrap5/issues/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

yakky avatar Jul 20 '23 09:07 yakky

Just a draft idea to address https://github.com/zostera/django-bootstrap5/issues/267 to see if there is any interesting in solving the issue

Yes, please merge these changes.

apapsch avatar Apr 16 '24 08:04 apapsch

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

yakky avatar Apr 27 '24 09:04 yakky

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

dyve avatar Apr 27 '24 10:04 dyve

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

yakky avatar Apr 27 '24 13:04 yakky

Ok, Let's see it.

dyve avatar Apr 27 '24 13:04 dyve

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

yakky avatar Apr 27 '24 19:04 yakky

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.

Fingel avatar Oct 27 '24 18:10 Fingel

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.

don-philipe avatar Nov 04 '24 11:11 don-philipe

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 avatar Nov 19 '24 15:11 francoisfreitag

https://github.com/zostera/django-bootstrap5/pull/524#issuecomment-2485984608

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

francoisfreitag avatar Dec 16 '24 08:12 francoisfreitag

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

dyve avatar Dec 16 '24 09:12 dyve

See #737

dyve avatar Dec 16 '24 09:12 dyve

@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.

dyve avatar Dec 16 '24 09:12 dyve

Closing because this will be fixed in #737

dyve avatar Mar 01 '25 10:03 dyve