Answer the question
In order to leave comments, you need to log in
Django. More efficient method of hiding fields in a template?
Hello! Now the fields in the search form are hidden with the following condition:
$('#category_id').change(function () {
var optionSelected = $("option:selected", this);
var valueSelected = $(this).val();
if (valueSelected === '1') {
$('#rooms_id').hide();
$('#series_id').hide();
} else if (valueSelected === '2') {
$('#rooms_id').hide();
$('#series_id').hide();
} else {
$('#rooms_id').show();
$('#series_id').show();
}
<div class="col-md-3 mb-3">
<label class="sr-only">Категории</label>
<select name="category" class="form-control" id="category_id">
<option selected="true" disabled="disabled">Категории</option>
{% for category in categories %}
<option value="{{ category.pk }}">{{ category.name }}</option>
{% endfor %}
</select>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question