From fb077bc5574e90bcc498feb92e7047c88af18a54 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Thu, 25 May 2023 19:11:58 +0200 Subject: [PATCH] Validate ComboBoxes --- Elwig/Windows/AdministrationWindow.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index 15be937..80bed34 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -201,6 +201,7 @@ namespace Elwig.Windows { Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id); if (list != null && ortInput.SelectedItem == null && list.Count == 1) ortInput.SelectedItem = list[0]; + UpdateComboBox(ortInput); } protected bool InputTextChanged(TextBox input, Func checker) { @@ -280,22 +281,31 @@ namespace Elwig.Windows { UpdateButtons(); } - protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) { - var input = (ComboBox)sender; - if (input.ItemsSource != null && input.SelectedItem == null && RequiredInputs.Contains(input)) { - ValidateInput(input, false); - Utils.SetInputInvalid(input); - } else { + private void UpdateComboBox(Control input) { + bool valid = false; + if (input is ComboBox cb) { + valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input); + } else if (input is CheckComboBox ccb) { + valid = ccb.ItemsSource == null || ccb.SelectedItem != null || !RequiredInputs.Contains(input); + } + if (valid) { ValidateInput(input, true); if (InputHasChanged(input)) { Utils.SetInputChanged(input); } else { Utils.ClearInputState(input); } + } else { + ValidateInput(input, false); + Utils.SetInputInvalid(input); } UpdateButtons(); } + protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) { + UpdateComboBox((Control)sender); + } + protected void IntegerInput_TextChanged(object sender, RoutedEventArgs evt) { InputTextChanged((TextBox)sender, Validator.CheckInteger); }