django-bootstrap4
django-bootstrap4 copied to clipboard
Add form submit attributes (like `formaction`) to buttons
See also: https://caniuse.com/#feat=form-submit-attributes
This would be awesome considering that form
elements are not allowed to be nested. For constructing a formset with some buttons that do something with individual objects (move up/down, delete, ...) there are currently no good options.
- Making the layout so that the forms aren't nested is a pain and shouldn't be necessary.
- Detecting that we actually want to do something completely different than edit the entire formset on the server is hacky.
- The best option by far of course is to just write the button element by hand instead of using the
bootstrap_button
tag. But it would still be nice not to have to do that.
If this is considered a worthwhile addition, I'm prepared to implement it.
Adding actions and maybe other attributes to buttons would be cool.
I'm also thinking of simplifying the widgets to templates, or perhaps dropping button support entirely, since it's often easier to just code the buttons manually.
Feel free to discuss a solution or even to submit a PR.
I already made #178 back then! It's not a very inspired solution, though, just more parameters for buttons.
Buttons are handled differently from fields in forms.py right now - fields take attributes as **kwargs
, so adding new attributes to them is much easier. Perhaps it would be possible to refactor buttons to make them work in a similar way?
I did something similar for django-bootstrap3
back in the day: My old PR
In this PR, I also make using data attributes possible by converting attributes starting with data_
(and only those, for maximum backwards-compatibility) by substituting dashes for underscores.
Supporting data attributes would probably be a good idea anyway?
In any case, I think that making buttons less restrictive would be awesome and better than dropping support for them - less restrictions to work around would also mean that they are easier to use.
Let me know what you think, I'd definitely consider doing what I just suggested if you agree that it's a good idea (although unfortunately, to be completely honest, I can't really promise anything - many small jobs that all need to be done from home with few boundaries might make that difficult).
I came across this same problem in django-bootstrap5. Buttons need more options. Thanks for your patience on this.
I think this is what you mean (in django-bootstrap5): https://github.com/zostera/django-bootstrap5/pull/79
Note that this does not cover data attributes, we'll cover that in a separate issue.