From 8145924b37670905de5999ce66a3b1c367270994 Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 30 Jun 2026 09:07:01 +0200 Subject: [PATCH 1/6] Add clear button to calendar drawer --- app/qml/form/components/MMCalendarDrawer.qml | 20 +++++++++++++++++++ app/qml/form/editors/MMFormCalendarEditor.qml | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/app/qml/form/components/MMCalendarDrawer.qml b/app/qml/form/components/MMCalendarDrawer.qml index 5e804dfae..0134574df 100644 --- a/app/qml/form/components/MMCalendarDrawer.qml +++ b/app/qml/form/components/MMCalendarDrawer.qml @@ -24,11 +24,31 @@ MMComponents.MMDrawer { property bool showSeconds: false signal primaryButtonClicked + signal clearButtonClicked dim: true drawerHeader.title: root.title + drawerHeader.topLeftItemContent: [ + MMComponents.MMButton { + text: qsTr("Clear") + type: MMComponents.MMButton.Types.Tertiary + size: MMComponents.MMButton.Sizes.Small + + anchors { + left: parent.left + leftMargin: __style.pageMargins + __style.safeAreaLeft + verticalCenter: parent.verticalCenter + } + + onClicked: { + root.clearButtonClicked() + root.close() + } + } + ] + drawerContent: Item { width: parent.width height: scrollView.height diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index 12632ac49..d63e1d705 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -105,6 +105,10 @@ MMPrivateComponents.MMBaseSingleLineInput { root.newDateSelected( dateTime ) } + onClearButtonClicked: { + root.editorValueChanged( root._fieldValue, true ) + } + onClosed: dateTimeDrawerLoader.active = false Component.onCompleted: open() From d76002c4353bf1972322148d7ba1a847cfcc0659 Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 30 Jun 2026 16:09:15 +0200 Subject: [PATCH 2/6] Fix clearing calendar field causing runtime error --- app/qml/form/editors/MMFormCalendarEditor.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index d63e1d705..916a0143a 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -96,7 +96,7 @@ MMPrivateComponents.MMBaseSingleLineInput { id: dateTimeDrawer title: root._fieldTitle - dateTime: root._fieldValueIsNull || root._fieldHasMixedValues ? new Date() : dateTransformer.toJsDate( root._fieldValue ) + dateTime: root.hasValidFieldValue() ? new Date() : dateTransformer.toJsDate( root._fieldValue ) hasDatePicker: root.includesDate hasTimePicker: root.includesTime showSeconds: root.showSeconds @@ -126,6 +126,13 @@ MMPrivateComponents.MMBaseSingleLineInput { } } + function hasValidFieldValue() { + return root._fieldValueIsNull + || root._fieldHasMixedValues + || root._fieldValue === undefined + || root._fieldValue === null + } + QtObject { id: dateTransformer // When changing this function, test with various timezones! From a5552f802f39823d61b563405afa9b3f786642c7 Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 30 Jun 2026 17:29:17 +0200 Subject: [PATCH 3/6] Add hide calendar clear button for empty values feature --- app/qml/form/components/MMCalendarDrawer.qml | 16 ++++++---------- app/qml/form/editors/MMFormCalendarEditor.qml | 1 + 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/qml/form/components/MMCalendarDrawer.qml b/app/qml/form/components/MMCalendarDrawer.qml index 0134574df..d06a756c0 100644 --- a/app/qml/form/components/MMCalendarDrawer.qml +++ b/app/qml/form/components/MMCalendarDrawer.qml @@ -22,6 +22,7 @@ MMComponents.MMDrawer { property alias hasDatePicker: dateTimePicker.hasDatePicker property alias hasTimePicker: dateTimePicker.hasTimePicker property bool showSeconds: false + property bool fieldValueIsNull: true signal primaryButtonClicked signal clearButtonClicked @@ -30,24 +31,19 @@ MMComponents.MMDrawer { drawerHeader.title: root.title - drawerHeader.topLeftItemContent: [ + drawerHeader.topLeftItem.visible: !root.fieldValueIsNull + drawerHeader.topLeftItemContent: MMComponents.MMButton { text: qsTr("Clear") - type: MMComponents.MMButton.Types.Tertiary - size: MMComponents.MMButton.Sizes.Small - - anchors { - left: parent.left - leftMargin: __style.pageMargins + __style.safeAreaLeft - verticalCenter: parent.verticalCenter - } + type: MMButton.Types.Tertiary + fontColor: __style.darkGreyColor + fontColorHover: __style.nightColor onClicked: { root.clearButtonClicked() root.close() } } - ] drawerContent: Item { width: parent.width diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index 916a0143a..fb1025f94 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -100,6 +100,7 @@ MMPrivateComponents.MMBaseSingleLineInput { hasDatePicker: root.includesDate hasTimePicker: root.includesTime showSeconds: root.showSeconds + fieldValueIsNull: root._fieldValueIsNull onPrimaryButtonClicked: { root.newDateSelected( dateTime ) From 5a7753271d6572e5a2d277cd4cdaff2644e00de1 Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 14 Jul 2026 13:36:38 +0200 Subject: [PATCH 4/6] Update code to be more consistent and easier to read --- app/qml/form/components/MMCalendarDrawer.qml | 5 ++--- app/qml/form/editors/MMFormCalendarEditor.qml | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/qml/form/components/MMCalendarDrawer.qml b/app/qml/form/components/MMCalendarDrawer.qml index d06a756c0..1b0032c98 100644 --- a/app/qml/form/components/MMCalendarDrawer.qml +++ b/app/qml/form/components/MMCalendarDrawer.qml @@ -22,7 +22,7 @@ MMComponents.MMDrawer { property alias hasDatePicker: dateTimePicker.hasDatePicker property alias hasTimePicker: dateTimePicker.hasTimePicker property bool showSeconds: false - property bool fieldValueIsNull: true + property bool showClearButton: true signal primaryButtonClicked signal clearButtonClicked @@ -30,8 +30,7 @@ MMComponents.MMDrawer { dim: true drawerHeader.title: root.title - - drawerHeader.topLeftItem.visible: !root.fieldValueIsNull + drawerHeader.topLeftItem.visible: !root.showClearButton drawerHeader.topLeftItemContent: MMComponents.MMButton { text: qsTr("Clear") diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index fb1025f94..5fba6c53c 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -100,14 +100,14 @@ MMPrivateComponents.MMBaseSingleLineInput { hasDatePicker: root.includesDate hasTimePicker: root.includesTime showSeconds: root.showSeconds - fieldValueIsNull: root._fieldValueIsNull + showClearButton: root._fieldValueIsNull onPrimaryButtonClicked: { root.newDateSelected( dateTime ) } onClearButtonClicked: { - root.editorValueChanged( root._fieldValue, true ) + root.editorValueChanged( undefined, true ) } onClosed: dateTimeDrawerLoader.active = false @@ -130,8 +130,7 @@ MMPrivateComponents.MMBaseSingleLineInput { function hasValidFieldValue() { return root._fieldValueIsNull || root._fieldHasMixedValues - || root._fieldValue === undefined - || root._fieldValue === null + || (root._fieldValue ?? null) === null } QtObject { From 4285fca76cfd9d17a2d0a23147e4e503a9c3d60e Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 21 Jul 2026 11:38:38 +0200 Subject: [PATCH 5/6] Refactor calendar clear code --- app/qml/form/editors/MMFormCalendarEditor.qml | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index 5fba6c53c..1fbe7a9ce 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -96,7 +96,7 @@ MMPrivateComponents.MMBaseSingleLineInput { id: dateTimeDrawer title: root._fieldTitle - dateTime: root.hasValidFieldValue() ? new Date() : dateTransformer.toJsDate( root._fieldValue ) + dateTime: root.hasInvalidFieldValue() ? new Date() : dateTransformer.toJsDate( root._fieldValue ) hasDatePicker: root.includesDate hasTimePicker: root.includesTime showSeconds: root.showSeconds @@ -107,7 +107,7 @@ MMPrivateComponents.MMBaseSingleLineInput { } onClearButtonClicked: { - root.editorValueChanged( undefined, true ) + root.editorValueChanged( null, true ) } onClosed: dateTimeDrawerLoader.active = false @@ -119,18 +119,14 @@ MMPrivateComponents.MMBaseSingleLineInput { function openCalendar() { forceActiveFocus() - if (root._fieldValueIsNull || _fieldHasMixedValues) { - root.openPicker( new Date() ) - } - else { - root.openPicker( dateTransformer.toJsDate(root._fieldValue) ) - } + dateTimeDrawerLoader.active = true + dateTimeDrawerLoader.focus = true } - function hasValidFieldValue() { + function hasInvalidFieldValue() { return root._fieldValueIsNull || root._fieldHasMixedValues - || (root._fieldValue ?? null) === null + || (root._fieldValue ?? true) } QtObject { @@ -197,9 +193,4 @@ MMPrivateComponents.MMBaseSingleLineInput { return Qt.formatDateTime(jsDate, root._fieldConfig['display_format']) } } - - function openPicker(requestedDate) { - dateTimeDrawerLoader.active = true - dateTimeDrawerLoader.focus = true - } } From 241f97d4bbe2962c0fcb84edebe126310d01e936 Mon Sep 17 00:00:00 2001 From: Richard Kello Date: Tue, 21 Jul 2026 11:43:31 +0200 Subject: [PATCH 6/6] Update some logic to be easier to understand --- app/qml/form/components/MMCalendarDrawer.qml | 4 ++-- app/qml/form/editors/MMFormCalendarEditor.qml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/qml/form/components/MMCalendarDrawer.qml b/app/qml/form/components/MMCalendarDrawer.qml index 1b0032c98..f83b76fda 100644 --- a/app/qml/form/components/MMCalendarDrawer.qml +++ b/app/qml/form/components/MMCalendarDrawer.qml @@ -22,7 +22,7 @@ MMComponents.MMDrawer { property alias hasDatePicker: dateTimePicker.hasDatePicker property alias hasTimePicker: dateTimePicker.hasTimePicker property bool showSeconds: false - property bool showClearButton: true + property bool showClearButton: false signal primaryButtonClicked signal clearButtonClicked @@ -30,7 +30,7 @@ MMComponents.MMDrawer { dim: true drawerHeader.title: root.title - drawerHeader.topLeftItem.visible: !root.showClearButton + drawerHeader.topLeftItem.visible: root.showClearButton drawerHeader.topLeftItemContent: MMComponents.MMButton { text: qsTr("Clear") diff --git a/app/qml/form/editors/MMFormCalendarEditor.qml b/app/qml/form/editors/MMFormCalendarEditor.qml index 1fbe7a9ce..e53065d1e 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -100,7 +100,7 @@ MMPrivateComponents.MMBaseSingleLineInput { hasDatePicker: root.includesDate hasTimePicker: root.includesTime showSeconds: root.showSeconds - showClearButton: root._fieldValueIsNull + showClearButton: !root._fieldValueIsNull onPrimaryButtonClicked: { root.newDateSelected( dateTime )