Skip to content

Commit

Permalink
fix!: add missing hours worked field and properly toggle based on rad…
Browse files Browse the repository at this point in the history
…io buttons
  • Loading branch information
MaddyUnderStars committed Oct 14, 2024
1 parent 6b32e05 commit 1aaf885
Showing 1 changed file with 54 additions and 15 deletions.
69 changes: 54 additions & 15 deletions system/modules/timelog/templates/edit.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<span class="form-check d-inline ps-0">
<?php
echo new Radio([
"id" => "select_end_method_time",
"name" => "select_end_method",
"class" => "",
"select" => "form-check-input",
Expand Down Expand Up @@ -175,31 +176,45 @@
<span class="form-check d-inline ps-0">
<?php
echo new Radio([
"id" => "select_end_method_hours",
"name" => "select_end_method",
"class" => "",
"select" => "form-check-input",
"value" => "time",
"value" => "hours",
"tabindex" => -1
]);
?>
</span>

<span class="d-inline">
<label class="form-label d-inline-flex" for="time_end">
<label class="form-label d-inline-flex" for="hours_worked">
Hours/Minutes worked
</label>
<?php
echo new Number([
"id|name" => "time_end",
"class" => "form-control",
"value" => $timelog->getMinutesWorked(),
"min" => 0,
"max" => 59,
"step" => 1,
"placeholder" => "Mins: 0-59",
"disabled" => "true"
])
?>
<div class="d-flex gap-2">
<?php
echo new Number([
"id|name" => "hours_worked",
"class" => "form-control",
"value" => $timelog->getHoursWorked(),
"min" => 0,
"max" => 23,
"step" => 1,
"placeholder" => "Hours: 0-23",
"disabled" => "true"
]);

echo new Number([
"id|name" => "minutes_worked",
"class" => "form-control",
"value" => $timelog->getMinutesWorked(),
"min" => 0,
"max" => 59,
"step" => 1,
"placeholder" => "Mins: 0-59",
"disabled" => "true"
])
?>
</div>
</span>
</div> <!-- hours/minutes -->
</div> <!-- end time inputs -->
Expand Down Expand Up @@ -236,4 +251,28 @@
<?php endif; ?> <!-- additional fields -->

<button type="submit" class="btn btn-primary ms-0">Submit</button>
</form>
</form>

<script>
const handleRadioChange = (e) => {
const value = e.target.value;

const time_end = document.getElementById("time_end");
const hours_worked = document.getElementById("hours_worked");
const minutes_worked = document.getElementById("minutes_worked");

if (value === "time") {
hours_worked.setAttribute("disabled", "disabled");
minutes_worked.setAttribute("disabled", "disabled");
time_end.removeAttribute("disabled");
}
else {
hours_worked.removeAttribute("disabled");
minutes_worked.removeAttribute("disabled");
time_end.setAttribute("disabled", "disabled");
}
}

document.getElementById("select_end_method_hours").addEventListener("change", handleRadioChange);
document.getElementById("select_end_method_time").addEventListener("change", handleRadioChange);
</script>

0 comments on commit 1aaf885

Please sign in to comment.