diff --git a/app/javascript/activities.js b/app/javascript/activities.js
index 5af41a275..8bbff2089 100644
--- a/app/javascript/activities.js
+++ b/app/javascript/activities.js
@@ -5,6 +5,24 @@ document.addEventListener('turbo:load', () => {
if (element) {
const priceLists = JSON.parse(element.dataset.priceLists);
+ // Keep the activity's duration when the start time is changed
+ const startInput = element.querySelector('#activity_start_time');
+ const endInput = element.querySelector('#activity_end_time');
+ if (startInput && endInput) {
+ let previousStart = startInput.value;
+ startInput.addEventListener('change', () => {
+ const oldStart = new Date(previousStart);
+ const newStart = new Date(startInput.value);
+ const oldEnd = new Date(endInput.value);
+ previousStart = startInput.value;
+ if ([oldStart, newStart, oldEnd].some(d => isNaN(d))) return;
+
+ const newEnd = new Date(oldEnd.getTime() + (newStart - oldStart));
+ const pad = n => String(n).padStart(2, '0');
+ endInput.value = `${newEnd.getFullYear()}-${pad(newEnd.getMonth() + 1)}-${pad(newEnd.getDate())}T${pad(newEnd.getHours())}:${pad(newEnd.getMinutes())}`;
+ });
+ }
+
mountVue(element, {
data: () => ({
query: '',
diff --git a/app/views/activities/_modal.html.erb b/app/views/activities/_modal.html.erb
index 45eba0716..828e59db6 100644
--- a/app/views/activities/_modal.html.erb
+++ b/app/views/activities/_modal.html.erb
@@ -9,8 +9,10 @@
<%= simple_form_for @activity, wrapper: :horizontal_form, html: { class: 'needs-validation' } do |f| %>
<%= f.input :title, label: 'Titel', placeholder: 'Titel', required: true %>
- <%= f.input :start_time, as: :string, label: 'Begintijd', required: true, order: %i[hour minute day month year] %>
- <%= f.input :end_time, as: :string, label: 'Eindtijd', required: true, order: %i[hour minute day month year] %>
+ <%= f.input :start_time, as: :string, label: 'Begintijd', required: true,
+ input_html: { type: 'datetime-local', step: 300, value: f.object.start_time&.strftime('%Y-%m-%dT%H:%M') } %>
+ <%= f.input :end_time, as: :string, label: 'Eindtijd', required: true,
+ input_html: { type: 'datetime-local', step: 300, value: f.object.end_time&.strftime('%Y-%m-%dT%H:%M') } %>