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
16 changes: 16 additions & 0 deletions app/qml/form/components/MMCalendarDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,29 @@ MMComponents.MMDrawer {
property alias hasDatePicker: dateTimePicker.hasDatePicker
property alias hasTimePicker: dateTimePicker.hasTimePicker
property bool showSeconds: false
property bool fieldValueIsNull: true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to have another property just set the value to null


signal primaryButtonClicked
signal clearButtonClicked
Comment on lines 27 to +28

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe at this point we can have just one signal which says user finished picking the value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that now this was mentioned in the ticket to create it


dim: true

drawerHeader.title: root.title

drawerHeader.topLeftItem.visible: !root.fieldValueIsNull

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visibility based on dateTime value

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

onClicked: {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the the value to null here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or empty Date()

root.clearButtonClicked()
root.close()
}
}

drawerContent: Item {
width: parent.width
height: scrollView.height
Expand Down
14 changes: 13 additions & 1 deletion app/qml/form/editors/MMFormCalendarEditor.qml
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.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 )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently the actual value doesn't change we just flag it as null no?

}

onClosed: dateTimeDrawerLoader.active = false

Component.onCompleted: open()
Expand All @@ -122,6 +127,13 @@ MMPrivateComponents.MMBaseSingleLineInput {
}
}

function hasValidFieldValue() {
return root._fieldValueIsNull
|| root._fieldHasMixedValues
|| root._fieldValue === undefined
|| root._fieldValue === null
Comment on lines +133 to +134

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future this can be replaced with ?? (nullish coalescence operator), it probably won't simplify it here

}

QtObject {
id: dateTransformer
// When changing this function, test with various timezones!
Expand Down
Loading