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

[REVIEW] 261 - Improve dropdown menu exhibition #454

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/ARte/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
class UploadFileForm(forms.Form):
file = forms.ImageField(required=False)

class ListTextWidget(forms.TextInput):
def __init__(self, *args, **kwargs):
super(ListTextWidget, self).__init__(*args, **kwargs)
self._name = 'exhibit-list'
self._list = Exhibit.objects.all().order_by('name')
self.attrs.update({'list':f'list__{self._name}'})

def render(self, name, value, attrs=None, renderer=None):
text_html = super(ListTextWidget, self).render(name, value, attrs=attrs)
data_list = f'<datalist id="list__{self._name}">'
for item in self._list:
data_list += f'<option value="{item.slug}">{item.name}</option>'
data_list += '</datalist>'
return (text_html + data_list)

class ExhibitForm(forms.Form):
exhibit = forms.ModelChoiceField(queryset=Exhibit.objects.all().order_by('name'))
exhibit = forms.CharField(required=True)

def __init__(self, *args, **kwargs):
super(ExhibitForm, self).__init__(*args, **kwargs)
self.fields['exhibit'].widget = ListTextWidget()
self.fields['exhibit'].label = ""
28 changes: 2 additions & 26 deletions src/ARte/core/jinja2/core/exhibit_select.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,16 @@

<div class="exhibit-form">
<h2>{{_("Choose the Exhibition you're seeing")}}</h2>
<div class="search-area">
<input type="text" id="search-box" name="search" onkeyup="findExhibit()" autocomplete="off" />
</div>
<form name="exhibit-form" action="{{url('exhibit_select')}}" method="post">
<form name="exhibit-form" action="{{url('exhibit_select')}}" method="post" autocomplete="off">
{{ csrf_input }}
{% for field in form.visible_fields() %}
<p class="exhibit-field {{field.name}}">
{{ field }}
{{ field.errors }}
</p>
{% endfor %}
{{form}}
<input class="submit-btn" type="submit" value="{{ _('Submit') }}"/>
</form>
</div>
</div>
<script>
let field = document.getElementById('id_exhibit');
field.style="padding: 0";

function findExhibit() {
let field = document.getElementById('id_exhibit').options;
let searchValue = document.getElementById("search-box").value;
for (keys in field) {
if (field[keys].innerHTML !== undefined) {
let valueField = field[keys].innerHTML
if (valueField.toUpperCase().indexOf(searchValue.toUpperCase()) > -1 && searchValue != "") {
field[keys].selected = "selected";
} else {
field[keys].selected = "";
}
}
}
}

$('#id_exhibit').on('change',function(e){
if($(this).prop('value') != ''){
$('input[type="submit"]').prop('disabled', false);
Expand Down
2 changes: 1 addition & 1 deletion src/ARte/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def exhibit_select(request):
form = ExhibitForm(request.POST)
if form.is_valid():
exhibit = form.cleaned_data.get('exhibit')
return redirect("/" + exhibit.slug)
return redirect("/" + exhibit)
else:
form = ExhibitForm()

Expand Down