Hi everyone,
Here is my current case. For development, I used a UL/LI pattern for rendering a dropdown menu within a search bar.
now, the backend start to getting life and the prepopulated data become database data.
I made a very basic form for the moment, working incrementally as much as possible.
the CSS in not just plain dropdown menu.
You can check the image how it’s look like.
Here is the code of the
- and
-
<ul id="searchbar-in-dropdown-menu" role="listbox" aria-labelledby="searchbar-in-cat-label" class="searchbar-in-dropdown-menu"> {% for choice in form.categoryList %} <!-- {{ cat.get_absolute_url }} --> <li class="categorie-dropdown-list-item" role="option" aria-selected="false" onclick="dropdownItemSelected({{forloop.counter0}})"> <div class="categorie-dropdown-item-div" aria-expanded="false" aria-haspopup="true"> <svg fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" height="32" width="32"><g fill="#3e4153"><path d="M20.45 4h-5.67a.51.51 0 00-.5.5.5.5 0 00.5.5H20v5.17a3.351 3.351 0 01-.84 2.48l-8 7.9a1.76 1.76 0 01-1.25.51 1.78 1.78 0 01-1.25-.51l-4-4A2.26 2.26 0 014 14.91a2.23 2.23 0 01.66-1.59c0-.05 5.37-5.14 6.56-6.34a.481.481 0 000-.7.5.5 0 00-.71 0C9.28 7.46 4 12.54 3.91 12.6a3.26 3.26 0 000 4.62l4 4a2.7 2.7 0 002 .81 2.771 2.771 0 002-.8l8-7.94A4.32 4.32 0 0021 10.17V4.5a.5.5 0 00-.55-.5z"></path><path d="M17 10a2 2 0 10-1.41-.58A1.94 1.94 0 0017 10zm-1-2a1 1 0 112 0 1 1 0 01-2 0zM10.86 11.84l.63-.63a1.48 1.48 0 00-2-.19L9 10.5l-.49.5.51.51a1.49 1.49 0 00.13 2.06c.63.64 1.32.53 2.23.09.71-.35 1.09-.42 1.39-.12a.76.76 0 01-.06 1.16.88.88 0 01-1.37 0l-.63.62a1.61 1.61 0 002.28.15l.52.51.49-.48-.56-.5a1.53 1.53 0 00-.09-2.15c-.57-.58-1.18-.58-2.26-.06-.68.3-1 .42-1.37.08a.67.67 0 010-1 .74.74 0 011.14-.03z"></path></g></svg> <span id="categoryId">{{ choice }}</span> </div> </li> {% endfor %} </ul>
I need to turn it into Select or anything else. So when the client press the search button (rightmost button), the server will receive the selected option.
I tried many way but Select/Option cant have extra div. The icon can’t be removed.
the form is very simple and anything can be changed to fit the client requirement.
The forms
class AdsSearchForm(forms.Form): searchBarInput = forms.CharField(required=False, label="Que recherchez-vous ?", max_length=255, widget=forms.TextInput(attrs={"id":"main-searchbar-input-text", "class":"main-searchbar-input-text" })) categoryList = forms.ModelChoiceField(queryset= Categorie.objects.all(), required=False)
I dont think the model pattern is relevant here. If needed I’ll post it.
The user select any dropdown choice and then the server parse the choice.
As you can see, actually I use an for-loop to show the choice. I can change everything on backend side and I can change everything on frontend side as long as the look remain the same.
Thank you.