This commit is contained in:
2022-05-23 21:16:36 +01:00
parent 25386026af
commit d631ad0223
41 changed files with 544 additions and 256 deletions
@@ -51,6 +51,13 @@ namespace Saxonite.Net.Core.Web.Admin.Models
return true;
return false;
}
/// <summary>Have any address values been populated on the form.</summary>
public bool IsPopulated()
{
if (SysId.IsValid(Id.ToSysId()) || !StringUtil.IsEmpty(Line1) || !StringUtil.IsEmpty(Town) || !StringUtil.IsEmpty(Province) || !StringUtil.IsEmpty(Country) || !StringUtil.IsEmpty(PostalCode))
return true;
return false;
}
//-------------------------------------------------------------------
// Validation.
@@ -58,6 +65,8 @@ namespace Saxonite.Net.Core.Web.Admin.Models
// Address.
public bool ValidateAddressData(SaxController_Base.AjaxResponse_Data responseData)
{
// Are any properties populated.
bool populated = IsPopulated();
// Address Line 1 - optional.
if (Line1 != null)
@@ -89,11 +98,11 @@ namespace Saxonite.Net.Core.Web.Admin.Models
}
}
// Address Town - mandatory.
// Address Town - mandatory if any value populated.
if (Town != null)
{
responseData.SetControlValue(ControlNameSuffix + "Town", Town);
if (StringUtil.IsEmpty(Town))
if (StringUtil.IsEmpty(Town) && populated)
responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.mandatory.value"]);
else if (StringUtil.GetLength(Town) > Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town))
responseData.SetControlError(ControlNameSuffix + "Town", Model.Localiser["msg.validation.maximum.length", Model.GetControlMaxLength(SaxDbDfn_Core.ColumnIdx.ItemAddress_Town)]);