From 76de196ee6a8fbca204d5b255b41c4767cc66590 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Wed, 14 Feb 2024 14:42:31 +0000 Subject: [PATCH] [Hosts]Indicate when an entry input field is invalid (#31407) * [Hosts]Indicate when an entry input field is invalid * Minor styling fix * Update src/modules/Hosts/Hosts/Strings/en-us/Resources.resw Co-authored-by: Davide Giacometti * Update src/modules/Hosts/Hosts/Strings/en-us/Resources.resw Co-authored-by: Davide Giacometti * Change messages to "Has to be" --------- Co-authored-by: Niels Laute Co-authored-by: Davide Giacometti --- .../Hosts/Hosts/HostsXAML/Views/MainPage.xaml | 35 +++++++++++++++++-- src/modules/Hosts/Hosts/Models/Entry.cs | 18 +++++++++- .../Hosts/Hosts/Strings/en-us/Resources.resw | 6 ++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/modules/Hosts/Hosts/HostsXAML/Views/MainPage.xaml b/src/modules/Hosts/Hosts/HostsXAML/Views/MainPage.xaml index fd9484d05b..e8bd576b95 100644 --- a/src/modules/Hosts/Hosts/HostsXAML/Views/MainPage.xaml +++ b/src/modules/Hosts/Hosts/HostsXAML/Views/MainPage.xaml @@ -450,7 +450,23 @@ + Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> + + + + + + + + TextWrapping="Wrap"> + + + + + + + Validate(true); + public bool IsAddressValid => ValidateAddressField(); + + public bool IsHostsValid => ValidateHostsField(true); + public string Line { get; private set; } public AddressType Type { get; private set; } @@ -152,6 +158,16 @@ namespace Hosts.Models }; } + private bool ValidateAddressField() + { + return Type != AddressType.Invalid; + } + + private bool ValidateHostsField(bool validateHostsLength) + { + return ValidationHelper.ValidHosts(Hosts, validateHostsLength); + } + public bool Validate(bool validateHostsLength) { if (Equals("102.54.94.97", "rhino.acme.com", "source server") || Equals("38.25.63.10", "x.acme.com", "x client host")) @@ -159,7 +175,7 @@ namespace Hosts.Models return false; } - return Type != AddressType.Invalid && ValidationHelper.ValidHosts(Hosts, validateHostsLength); + return ValidateAddressField() && ValidateHostsField(validateHostsLength); } private bool Equals(string address, string hosts, string comment) diff --git a/src/modules/Hosts/Hosts/Strings/en-us/Resources.resw b/src/modules/Hosts/Hosts/Strings/en-us/Resources.resw index 9b3a7bc810..4fba56fa05 100644 --- a/src/modules/Hosts/Hosts/Strings/en-us/Resources.resw +++ b/src/modules/Hosts/Hosts/Strings/en-us/Resources.resw @@ -299,6 +299,12 @@ Entries contain too many hosts "Hosts" refers to the system hosts file, do not loc + + Has to be a valid IPv4 or IPv6 address + + + Has to be one or more valid host names separated by spaces + Update