-
Notifications
You must be signed in to change notification settings - Fork 468
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
single-select autocomplete does not look good using django-bootstrap5 bootstrap_form #1318
Comments
It looks like adding Now I have to find how to do that custom styling. |
Ah, but it still has two arrows. Not sure how to fix that? |
If this helps anyone else, I added the hacks below to my CSS. Not sure if that is a good idea, but here we go.
|
Also: I could not find how to style just that box, so I just dumped this CSS in the page globally. Is there somewhere in the docs that talks about styling the widget? I saw I can pass select2 options (don't want that), and that I can style the results of the autocomplete view (don't want that). |
hey @dfrankow, thanks for the snippet. this helped me with the same issue. I hope there is an official less hacky solution in the future. |
@mordechaiyosef Thanks for letting me know! |
Hello @dfrankow , thank you very much, I also had the same issue and your "hack" helped a lot. BTW may be you can help with other similar issue, I'm trying to use autocomplete form with tag class = "form-control" and for some reason they have different width, comparing to just normal input forms, may be you have any suggestions how to fix that? I've tried to add attrs={'width':'500'} , but due to this form looses it's fluid size ability. |
My only suggestion is to use the browser css explorer to see which styles are applied to each of those boxes, and turn on and off various attributes until it looks the way you want. That's what I did, just experimented. |
@dfrankow You could use the bootstrap5 theme for select2.
|
@Actionb this doesnt seem to fix the issue |
Applying the theme should change the look. It certainly does for me. class MyForm(forms.Form):
single_select = forms.ChoiceField(
label="Not themed",
choices=[('foo', 'Foo'), ('bar', 'Bar'), ('spam', 'spam')],
widget=autocomplete.Select2()
)
single_select_themed = forms.ChoiceField(
label="Themed",
choices=[('foo', 'Foo'), ('bar', 'Bar'), ('spam', 'spam')],
widget=autocomplete.Select2(attrs={'data-theme': 'bootstrap-5'})
) Template: <head>
...
<!-- select2 bootstrap theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/select2-bootstrap-5-theme.css" />
<!-- bootstrap -->
{% bootstrap_css %}
{% bootstrap_javascript %}
...
</head>
<body>
<form>
{% bootstrap_form form layout="horizontal" %}
</form>
</body> |
@Actionb I am seeing multiple fields with different field sizes form:
template:
|
Oh you mean the width of the container? https://select2.org/appearance#container-width Set it like so: |
@Actionb it works! thanks a bunch :) |
Thanks a lot @mordechaiyosef @Actionb @dfrankow , this helped me a ton! |
Thank you for your solution it helped me ! I also had to add :
to make it look good. (and at the bottom of the page after the media files for form is loaded) |
Are all these changes backwards-compatible or for v5 only? |
Below is a screenshot of a single-select and multi-select form rendered with
{% bootstrap_form myform %}
, a tag from django-bootstrap5.Closed:
Open:
Unfortunately, I don't know a ton about bootstrap5 forms, so I don't know the exact styling it's missing, or how to customize it. I'd have to do more research.
For more details of form object, template, etc., see https://stackoverflow.com/questions/75249988/why-is-django-autocomplete-light-single-select-badly-styled-and-broken-when-mult.
The text was updated successfully, but these errors were encountered: