Hey, I’m new here and I need help. This may be a very stupid question, and it’s likely my HTML or JavaScript is completely wrong in the Template, but for the life of me I cannot get my View’s request.POST.get(‘filterDateStart’) and request.POST.get(‘filterDateEnd’) to ever receive any value that isn’t None. The View is working fine for other filtering criteria, it’s just the date widget that I cannot get to work.
Basically the problem seems to be related to a JS script I’m using the make the date filtering optional, disabling the date picker widget when the ‘All Dates’ radio button is selected.
This is my template:
<script>
function toggleDateInputs() {
const customDatesSelected = document.getElementById('customDates').checked;
const dateInputs = document.getElementById('dateRangeInputs');
const dateStart = document.getElementById('filterDateStart');
const dateEnd = document.getElementById('filterDateEnd');
if (customDatesSelected) {
dateStart.disabled = false;
dateEnd.disabled = false;
dateStart.required = true;
dateEnd.required = true;
} else {
dateStart.disabled = true;
dateEnd.disabled = true;
dateStart.required = false;
dateEnd.required = false;
}
}
</script>
<div class="container-fluid">
<div class="row">
<div class="col-2 light-grey card" style="border-radius: 0; background-color: rgb(232, 232, 232)">
<!-- This is the light grey container -->
<h4 class="mt-2">Custom Filters</h4>
<p>Customize your data set here.</p>
<form id="filterForm" method="POST" action="{% url 'analytics_results' %}">
{% csrf_token %}
<div class="mb-3">
<label for="result-filter" class="form-label">Filter by Bet Result</label>
<select class="form-select" name="result-filter" id="result-filter" required>
<option value="category-all">All Results</option>
<option value="Win">Win</option>
<option value="Lose">Lose</option>
<option value="Push">Push</option>
<option value="Pending">Pending</option>
</select>
</div>
<div class="mb-3">
<label for="tag-filter" class="form-label">Filter by Custom Tags</label>
<select class="form-select" id="tag-filter" required>
<option value="category-all">All Tags</option>
<option value="category1">tag 1</option>
<option value="category2">tag 2</option>
<option value="category3">tag 3</option>
<option value="category4">tag 4</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Select Date Option</label>
<p><i>(this will filter by the "Date added" attribute)</i></p>
<div>
<input type="radio" id="allDates" name="dateOption" value="all" checked onclick="toggleDateInputs()">
<label for="allDates">All Dates</label>
</div>
<div>
<input type="radio" id="customDates" name="dateOption" value="custom" onclick="toggleDateInputs()">
<label for="customDates">Custom Dates</label>
</div>
</div>
<div class="mb-3" id="dateRangeInputs">
<label for="filterDate" class="form-label">Date Range</label>
<input type="date" class="form-control" id="filterDateStart" name="filterDateStart" required disabled>
<input type="date" class="form-control mt-2" id="filterDateEnd" name="filterDateEnd" required disabled>
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-primary btn-lg m-2 border border-dark">FILTER</button>
</div>
</form>