Validate ComboBoxes

This commit is contained in:
2023-05-25 19:11:58 +02:00
parent 9229f27cf7
commit fb077bc557

View File

@ -201,6 +201,7 @@ namespace Elwig.Windows {
Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id); Utils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
if (list != null && ortInput.SelectedItem == null && list.Count == 1) if (list != null && ortInput.SelectedItem == null && list.Count == 1)
ortInput.SelectedItem = list[0]; ortInput.SelectedItem = list[0];
UpdateComboBox(ortInput);
} }
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) { protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) {
@ -280,22 +281,31 @@ namespace Elwig.Windows {
UpdateButtons(); UpdateButtons();
} }
protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) { private void UpdateComboBox(Control input) {
var input = (ComboBox)sender; bool valid = false;
if (input.ItemsSource != null && input.SelectedItem == null && RequiredInputs.Contains(input)) { if (input is ComboBox cb) {
ValidateInput(input, false); valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input);
Utils.SetInputInvalid(input); } else if (input is CheckComboBox ccb) {
} else { valid = ccb.ItemsSource == null || ccb.SelectedItem != null || !RequiredInputs.Contains(input);
}
if (valid) {
ValidateInput(input, true); ValidateInput(input, true);
if (InputHasChanged(input)) { if (InputHasChanged(input)) {
Utils.SetInputChanged(input); Utils.SetInputChanged(input);
} else { } else {
Utils.ClearInputState(input); Utils.ClearInputState(input);
} }
} else {
ValidateInput(input, false);
Utils.SetInputInvalid(input);
} }
UpdateButtons(); UpdateButtons();
} }
protected void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) {
UpdateComboBox((Control)sender);
}
protected void IntegerInput_TextChanged(object sender, RoutedEventArgs evt) { protected void IntegerInput_TextChanged(object sender, RoutedEventArgs evt) {
InputTextChanged((TextBox)sender, Validator.CheckInteger); InputTextChanged((TextBox)sender, Validator.CheckInteger);
} }