diff --git a/app/qml/form/components/MMCalendarDrawer.qml b/app/qml/form/components/MMCalendarDrawer.qml index 5e804dfae..d06a756c0 100644 --- a/app/qml/form/components/MMCalendarDrawer.qml +++ b/app/qml/form/components/MMCalendarDrawer.qml @@ -22,13 +22,29 @@ MMComponents.MMDrawer { property alias hasDatePicker: dateTimePicker.hasDatePicker property alias hasTimePicker: dateTimePicker.hasTimePicker property bool showSeconds: false + property bool fieldValueIsNull: true signal primaryButtonClicked + signal clearButtonClicked dim: true drawerHeader.title: root.title + drawerHeader.topLeftItem.visible: !root.fieldValueIsNull + drawerHeader.topLeftItemContent: + MMComponents.MMButton { + text: qsTr("Clear") + type: MMButton.Types.Tertiary + fontColor: __style.darkGreyColor + fontColorHover: __style.nightColor + + 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..fb1025f94 100644 --- a/app/qml/form/editors/MMFormCalendarEditor.qml +++ b/app/qml/form/editors/MMFormCalendarEditor.qml @@ -96,15 +96,20 @@ 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 + fieldValueIsNull: root._fieldValueIsNull onPrimaryButtonClicked: { root.newDateSelected( dateTime ) } + onClearButtonClicked: { + root.editorValueChanged( root._fieldValue, true ) + } + onClosed: dateTimeDrawerLoader.active = false Component.onCompleted: open() @@ -122,6 +127,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!