OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Don't use native date fields for mobile safari
Henriette Dargec8821bf68f48
diff --git a/app/components/work_packages/date_picker/date_form_component.rb b/app/components/work_packages/date_picker/date_form_component.rbindex 5ed4e3127c5..bde178bfc9d 100644--- a/app/components/work_packages/date_picker/date_form_component.rb+++ b/app/components/work_packages/date_picker/date_form_component.rb@@ -80,7 +80,8 @@ module WorkPackagesshow_clear_button: show_clear_button?(name),classes: "op-datepicker-modal--date-field #{'op-datepicker-modal--date-field_current' if @focused_field == name}",validation_message: validation_message(name),- type: field_type(name)+ type: field_type(name),+ placeholder: placeholder(name))if duration_field?(name)@@ -176,7 +177,20 @@ module WorkPackagesdef field_type(name)return :number if duration_field?(name)- helpers.browser.device.mobile? ? :date : :text+ # Do not show the native datepicker on iOS safari because it+ # behaves totally different than all other browsers and destroys the behavior of the datepicker+ # Given a date field with no value: When Safari opens its native datepicker, the first thing it does is to+ # set the date to Today. And not only in the datepicker but directly in the field.+ # This behaviour has however consequences:+ # * The "reset" button in the datepicker does not clear the input (as the other browsers do it) but it resets+ # it to the original value it had when you opened it. So if the value was empty, it sets it back to empty.+ # If the value was set before, you cannot clear it, but only set it back to that value.+ # * Since the input changes, the whole datepicker updates without the user even knowing about it,+ # since the form is hidden behind the datepicker. That leads to this:+ # when you enter a start date after today, and then open the datepicker for finish date,+ # it will reset the start date because the finish date is set automatically to today,+ # but the finish date can't be before the start date.+ helpers.browser.device.mobile? && !helpers.browser.safari? ? :date : :textenddef validation_message(name)@@ -246,7 +260,11 @@ module WorkPackagesenddef show_clear_button?(name)- !disabled?(name) && !duration_field?(name) && !helpers.browser.device.mobile?+ !disabled?(name) && !duration_field?(name)+ end++ def placeholder(name)+ helpers.browser.device.mobile? && !duration_field?(name) ? "yyyy-mm-dd" : nilendendenddiff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.tsindex 28467267a80..2b2bf2e3c16 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts@@ -80,8 +80,6 @@ export default class PreviewController extends DialogPreviewController {document.addEventListener('date-picker:flatpickr-dates-changed', this.handleFlatpickrDatesChangedBound);this.focusOnOpen();-- this.prepareInputFieldsForSafari();}disconnect() {@@ -553,22 +551,4 @@ export default class PreviewController extends DialogPreviewController {tabs.focus();}}-- /*- * This method qualifies as the most stupid thing I had to do in a long time.- * Safari is the only browser which does not clear the input when using the native datepicker "clear" method.- * It rather resets it to the original value of the input.- * That is why we manually set the defaultValue to an empty string,- * but since the defaultValue is used for the value, we have to manually set this again.- * See: https://stackoverflow.com/a/64886383/8900797- */- private prepareInputFieldsForSafari() {- [this.startDateField, this.dueDateField]- .filter((field):field is NonNullable<typeof field> => field != null)- .forEach((field) => {- const value = field.value;- field.defaultValue = '';- field.value = value;- });- }}