DatePicker: Fix bug where switch from input to selection clears date text

This commit is contained in:
Florian Blasius 2024-06-14 07:40:52 +02:00 committed by Florian Blasius
parent 029ed7e4c2
commit 1d92d29649

View file

@ -464,13 +464,14 @@ export component DatePickerBase {
changed selection-mode => {
// check switch from input mode if input is valid
if root.ok-enabled() {
if root.selection-mode && root.current-input-valid() {
root.current-date = root.input-as-date();
root.display-date = root.current-date;
}
}
pure public function ok-enabled() -> bool {
root.selection-mode || SlintInternal.valid_date(root.current-input, root.input-format)
root.selection-mode || root.current-input-valid()
}
public function get-current-date() -> Date {
@ -481,6 +482,10 @@ export component DatePickerBase {
root.input-as-date()
}
pure function current-input-valid() -> bool {
SlintInternal.valid_date(root.current-input, root.input-format)
}
pure function input-as-date() -> Date {
{ day: root.input-formatted[0], month: root.input-formatted[1], year: root.input-formatted[2] }