To achieve this, you would need to add a JavaScript function that listens to the change event of the checkbox. When the checkbox is checked (half-day is selected), the 'Date To' field is hidden. Here's how you can modify your form to include this:
<form action="/my/leaves/new">
<!-- Existing form content... -->
<div class="form-group form-check col-sm-3 mt16 d-flex justify-content-center align-items-center">
<input class="form-check-input mr-2" type="checkbox" id="request_unit_half" name="request_unit_half" t-att-checked="leave.request_unit_half == True" t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};" onclick="showDateTo(this)"/>
<label class="form-check-label ml8" for="request_unit_half">
Half Day
</label>
</div>
<div class="form-group col-6" id="date_to_group">
<label for="date_to">Date To</label>
<input type="date" class="form-control" id="date_to" name="date_to" aria-describedby="date_to" placeholder="Date To" t-att-value="leave.request_date_from" t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};" required="1"/>
</div>
<!-- Existing form content... -->
</form>
<script>
function showDateTo(checkbox) {
var dateToGroup = document.getElementById("date_to_group");
if (checkbox.checked) {
dateToGroup.style.display = "none"; // Hide the Date To field when the checkbox is checked
} else {
dateToGroup.style.display = "block"; // Show the Date To field when the checkbox is unchecked
}
}
// Call the function on page load in case the checkbox is already checked
window.onload = function() {
var checkbox = document.getElementById("request_unit_half");
showDateTo(checkbox);
};
</script>
This script checks if the half-day checkbox is selected when the page loads, and hides the 'Date To' field if it is. It also sets up an event listener to hide/show the 'Date To' field whenever the checkbox is toggled.