Do not require ComboBoxes to be valid if they are not required

This commit is contained in:
2023-04-16 19:38:30 +02:00
parent e68a7ce8a9
commit 2c2ac46b2e
4 changed files with 7 additions and 18 deletions

View File

@ -1,15 +1,13 @@
using Elwig.Helpers;
using Elwig.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace Elwig.Windows {
public abstract class AdministrationWindow : ContextWindow {
protected Control[] ExemptInputs { private get; set; }
protected Control[] RequiredInputs { private get; set; }
private TextBox[] TextBoxInputs;
@ -66,14 +64,10 @@ namespace Elwig.Windows {
if (input is TextBox tb && tb.Text.Length == 0) {
Utils.SetInputInvalid(input);
Valid[input] = false;
} else if (input is ComboBox cb && cb.SelectedItem == null) {
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) {
Utils.SetInputInvalid(input);
}
}
foreach (var cb in ComboBoxInputs) {
if (cb.ItemsSource != null && cb.SelectedItem == null)
Utils.SetInputInvalid(cb);
}
}
protected void LockInputs() {
@ -155,8 +149,7 @@ namespace Elwig.Windows {
protected void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
if (plzInput.Text.Length == 4) {
int plz = int.Parse(plzInput.Text);
ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
ortInput.ItemsSource = Context.Postleitzahlen.Find(int.Parse(plzInput.Text))?.Orte.ToList();
} else {
ortInput.ItemsSource = null;
}