From 178164808c7a48be011f733eb2a866850626e40d Mon Sep 17 00:00:00 2001 From: networkException Date: Tue, 6 Sep 2022 18:19:58 +0200 Subject: [PATCH] Calendar: Limit the starting day input range to the selected month Previously we allowed entering any day value greater than one. With this patch the maximum input value is dynamic based on the selected month and year. --- Userland/Applications/Calendar/AddEventDialog.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/Calendar/AddEventDialog.cpp b/Userland/Applications/Calendar/AddEventDialog.cpp index 73a567f8bc..dd7965a952 100644 --- a/Userland/Applications/Calendar/AddEventDialog.cpp +++ b/Userland/Applications/Calendar/AddEventDialog.cpp @@ -63,8 +63,8 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) auto& starting_day_combo = middle_container.add(); starting_day_combo.set_fixed_size(40, 20); + starting_day_combo.set_range(1, m_date_time.days_in_month()); starting_day_combo.set_value(m_date_time.day()); - starting_day_combo.set_min(1); auto& starting_year_combo = middle_container.add(); starting_year_combo.set_fixed_size(55, 20); @@ -100,6 +100,16 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window) done(ExecResult::OK); }; + auto update_starting_day_range = [&starting_day_combo, &starting_year_combo, &starting_month_combo]() { + auto year = starting_year_combo.value(); + auto month = starting_month_combo.selected_index(); + + starting_day_combo.set_range(1, days_in_month(year, month + 1)); + }; + + starting_year_combo.on_change = [&update_starting_day_range](auto) { update_starting_day_range(); }; + starting_month_combo.on_change = [&update_starting_day_range](auto, auto) { update_starting_day_range(); }; + event_title_textbox.set_focus(true); }