Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/qml/form/components/MMCalendarDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,27 @@ MMComponents.MMDrawer {
property alias hasDatePicker: dateTimePicker.hasDatePicker
property alias hasTimePicker: dateTimePicker.hasTimePicker
property bool showSeconds: false
property bool showClearButton: false

signal primaryButtonClicked
signal clearButtonClicked
Comment thread
xkello marked this conversation as resolved.

dim: true

drawerHeader.title: root.title
drawerHeader.topLeftItem.visible: root.showClearButton
drawerHeader.topLeftItemContent:
MMComponents.MMButton {
text: qsTr("Clear")
type: MMButton.Types.Tertiary
fontColor: __style.darkGreyColor
fontColorHover: __style.nightColor

onClicked: {
Comment thread
xkello marked this conversation as resolved.
root.clearButtonClicked()
root.close()
}
}

drawerContent: Item {
width: parent.width
Expand Down
26 changes: 14 additions & 12 deletions app/qml/form/editors/MMFormCalendarEditor.qml
Comment thread
xkello marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@ MMPrivateComponents.MMBaseSingleLineInput {
id: dateTimeDrawer

title: root._fieldTitle
dateTime: root._fieldValueIsNull || root._fieldHasMixedValues ? new Date() : dateTransformer.toJsDate( root._fieldValue )
dateTime: root.hasInvalidFieldValue() ? new Date() : dateTransformer.toJsDate( root._fieldValue )
hasDatePicker: root.includesDate
hasTimePicker: root.includesTime
showSeconds: root.showSeconds
showClearButton: !root._fieldValueIsNull

onPrimaryButtonClicked: {
root.newDateSelected( dateTime )
}

onClearButtonClicked: {
root.editorValueChanged( null, true )
}

onClosed: dateTimeDrawerLoader.active = false

Component.onCompleted: open()
Expand All @@ -114,12 +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 hasInvalidFieldValue() {
return root._fieldValueIsNull
|| root._fieldHasMixedValues
|| (root._fieldValue ?? true)
}

QtObject {
Expand Down Expand Up @@ -186,9 +193,4 @@ MMPrivateComponents.MMBaseSingleLineInput {
return Qt.formatDateTime(jsDate, root._fieldConfig['display_format'])
}
}

function openPicker(requestedDate) {
dateTimeDrawerLoader.active = true
dateTimeDrawerLoader.focus = true
}
}
Loading