Skip to content

Commit

Permalink
fix behavior when we have disabled time tracking inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Dec 10, 2024
1 parent 5365457 commit 6d8d0cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ 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) {
this.datesChanged(event.currentTarget as HTMLInputElement);
}

datesChanged(initiatedBy:HTMLInputElement) {
if (!this.hasStartTimeInputTarget || !this.hasEndTimeInputTarget) {
return;
}

const startTimeParts = this.startTimeInputTarget.value.split(':');
const endTimeParts = this.endTimeInputTarget.value.split(':');

Expand Down
42 changes: 22 additions & 20 deletions modules/costs/app/components/time_entries/time_entry_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6d8d0cc

Please sign in to comment.