From 6d8d0cc4b707d4c5d38fca32d29a0f4b53ca45d6 Mon Sep 17 00:00:00 2001 From: Klaus Zanders Date: Tue, 10 Dec 2024 11:28:49 +0100 Subject: [PATCH] fix behavior when we have disabled time tracking inputs --- .../dynamic/time-entry.controller.ts | 6 +++ .../time_entries/time_entry_form.rb | 42 ++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts b/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts index 1a505b6f1709..69032cf8cd87 100644 --- a/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts +++ b/frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts @@ -35,7 +35,9 @@ export default class TimeEntryController extends Controller { static targets = ['startTimeInput', 'endTimeInput', 'hoursInput']; declare readonly startTimeInputTarget:HTMLInputElement; + declare readonly hasStartTimeInputTarget:boolean; declare readonly endTimeInputTarget:HTMLInputElement; + declare readonly hasEndTimeInputTarget:boolean; declare readonly hoursInputTarget:HTMLInputElement; timeInputChanged(event:InputEvent) { @@ -43,6 +45,10 @@ export default class TimeEntryController extends Controller { } datesChanged(initiatedBy:HTMLInputElement) { + if (!this.hasStartTimeInputTarget || !this.hasEndTimeInputTarget) { + return; + } + const startTimeParts = this.startTimeInputTarget.value.split(':'); const endTimeParts = this.endTimeInputTarget.value.split(':'); diff --git a/modules/costs/app/components/time_entries/time_entry_form.rb b/modules/costs/app/components/time_entries/time_entry_form.rb index 258a0894e1fb..74b0dcd0ca80 100644 --- a/modules/costs/app/components/time_entries/time_entry_form.rb +++ b/modules/costs/app/components/time_entries/time_entry_form.rb @@ -30,26 +30,28 @@ class TimeEntryForm < ApplicationForm value: model.spent_on&.iso8601, label: TimeEntry.human_attribute_name(:spent_on) - f.group(layout: :horizontal) do |g| - g.text_field name: :start_time, - type: "time", - required: true, - label: TimeEntry.human_attribute_name(:start_time), - value: model.start_timestamp&.strftime("%H:%M"), - data: { - "time-entry-target" => "startTimeInput", - "action" => "input->time-entry#timeInputChanged" - } - - g.text_field name: :end_time, - type: "time", - required: true, - label: TimeEntry.human_attribute_name(:end_time), - value: model.end_timestamp&.strftime("%H:%M"), - data: { - "time-entry-target" => "endTimeInput", - "action" => "input->time-entry#timeInputChanged" - } + if show_start_and_end_time_fields? + f.group(layout: :horizontal) do |g| + g.text_field name: :start_time, + type: "time", + required: true, + label: TimeEntry.human_attribute_name(:start_time), + value: model.start_timestamp&.strftime("%H:%M"), + data: { + "time-entry-target" => "startTimeInput", + "action" => "input->time-entry#timeInputChanged" + } + + g.text_field name: :end_time, + type: "time", + required: true, + label: TimeEntry.human_attribute_name(:end_time), + value: model.end_timestamp&.strftime("%H:%M"), + data: { + "time-entry-target" => "endTimeInput", + "action" => "input->time-entry#timeInputChanged" + } + end end f.text_field name: :hours,