Validate ComboBoxes
This commit is contained in:
@ -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<TextBox, bool, ValidationResult> 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user