<form action="/my/leaves/new"> <div class="card-header d-flex align-items-center…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
<div class="card-body">
<div class="row">
<div class="form-group col-6">
<label for="date_from">Date From</label>
<input type="date" class="form-control" id="date_from"
name="date_from" aria-describedby="date_from"
placeholder="Date From"
t-att-value="leave.request_date_from"
t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};"
required="1" />
</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>
<div class="form-group col-md-6 mt8" required="1">
<label for="holiday_status_id">Leave Type</label>
<select id="holiday_status_id" name="holiday_status_id"
class="form-control"
aria-describedby="holiday_status_id"
t-att-value="leave.holiday_status_id"
t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};">
<t t-foreach="leave_types" t-as="leave_type">
<option t-att-value="leave_type[3]"
t-att-selected="leave_type[3] == leave.holiday_status_id.id">
<t t-esc="leave_type[0]" />
</option>
</t>
</select>
</div>
<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'};" />
<label class="form-check-label ml8" for="request_unit_half">
Half Day
</label>
</div>
<div class="form-group col-sm-3 mt8">
<label for="duration_display">Duration</label>
<input type="text" class="form-control"
id="duration_display"
aria-describedby="duration_display"
placeholder="Duration"
t-att-value="leave.duration_display"
t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};" />
</div>
<div class="form-group col-12 mt8">
<label for="name">Description</label>
<textarea class="form-control" rows="3" name="name"
aria-describedby="description" t-raw="leave.name or ''"
t-attf-style="pointer-events: #{'none' if is_readonly else 'all'};" />
</div>
<div class="form-group col-md-6 mt8" id="file_upload_group"
style="display: none;">
<label for="supported_attachment_ids">Supporting Attachment</label>
<input type="file" id="supported_attachment_ids"
class="form-control"
aria-describedby="supported_attachment_ids"
style="pointer-events: all;" multiple="true" />
</div>
</div>
</div>
</form>
</div>
<!-- chatter -->
<div id="leaves_communication" class="mt-4" t-if="is_readonly">
<h2>History</h2>
<t t-call="portal.message_thread">
<t t-set="object" t-value="leave" />
</t>
</div>
</t>
</t>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var halfDayCheckbox = document.getElementById('request_unit_half');
var dateToGroup = document.getElementById('date_to_group');
var dateToInput = document.getElementById('date_to');
var dateFromInput = document.getElementById('date_from'); // Get the date_from input
var leaveTypeSelect = document.getElementById('holiday_status_id');
var fileUploadGroup = document.getElementById('file_upload_group');
var fileUploadInput = document.getElementById('supported_attachment_ids');
// Function to toggle the requirement and visibility of "Date To" and set its value
function toggleDateTo() {
var isHalfDay = halfDayCheckbox.checked;
// Toggle the visibility of the "Date To" input
dateToGroup.style.display = isHalfDay ? 'none' : 'block';
// Toggle the requirement of the "Date To" input and set its value
if (isHalfDay) {
dateToInput.removeAttribute('required');
dateToInput.value = dateFromInput.value; // Set date_to value to date_from
} else {
dateToInput.setAttribute('required', 'required');
dateToInput.value = ''; // Optional: Clear the value if half day is not selected
}
}
// Function to show/hide the file upload field based on leave type
function toggleFileUpload() {
var selectedLeaveType = leaveTypeSelect.value;
if (selectedLeaveType === "2") {
fileUploadGroup.style.display = 'block';
fileUploadInput.setAttribute('required', 'required');
} else {
fileUploadGroup.style.display = 'none';
fileUploadInput.removeAttribute('required');
}
}
// Add change event listener to the "Half Day" checkbox
leaveTypeSelect.addEventListener('change', toggleFileUpload);
halfDayCheckbox.addEventListener('change', toggleDateTo);
// Call the toggle function on initial page load to set the correct state
toggleDateTo();
});
</xpath>
</template>
modify the code such that once the halfday is selected also duration diseppear and morning and afternoon choice appear.Keep the rest of functionalities the same
To achieve the modifications you requested, you'll need to add two new elements to the HTML form: radio buttons for "Morning" and "Afternoon" selection, and modify the JavaScript to handle the new behavior for the duration field and the morning/afternoon selection when the "Half Day" checkbox is checked. Below is the modified code snippet:
Firstly, add the HTML for the new radio buttons:
<!-- Additional radio buttons for selecting Morning or Afternoon -->
<div class="form-group col-sm-6 mt8" id="half_day_options" style="display: none;">
<label>Half Day Options</label>
<div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="half_day_period" id="morning" value="morning">
<label class="form-check-label" for="morning">Morning</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="half_day_period" id="afternoon" value="afternoon">
<label class="form-check-label" for="afternoon">Afternoon</label>
</div>
</div>
</div>
Next, modify the JavaScript to toggle the visibility and requirement of the duration input and the morning/afternoon radio buttons based on the state of the "Half Day" checkbox:
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var halfDayCheckbox = document.getElementById('request_unit_half');
var dateToGroup = document.getElementById('date_to_group');
var durationDisplay = document.getElementById('duration_display');
var halfDayOptions = document.getElementById('half_day_options');
// Function to toggle the requirement and visibility of "Date To", "Duration", and "Half Day Options"
function toggleDateToAndDuration() {
var isHalfDay = halfDayCheckbox.checked;
// Toggle the visibility of the "Date To" input and "Duration" input
dateToGroup.style.display = isHalfDay ? 'none' : 'block';
durationDisplay.style.display = isHalfDay ? 'none' : 'block';
halfDayOptions.style.display = isHalfDay ? 'block' : 'none';
// Toggle the requirement of the "Date To" input and "Duration" input
if (isHalfDay) {