From d19becea1b762b5a8e18e26842d9119ec2365fc3 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 16 Jan 2019 19:52:57 +0000 Subject: [PATCH] --- server/AyaNova/biz/CustomFieldsValidator.cs | 10 ++++++++-- server/AyaNova/biz/FormAvailableFields.cs | 9 ++++++++- server/AyaNova/biz/RequiredFieldsValidator.cs | 20 +++++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/server/AyaNova/biz/CustomFieldsValidator.cs b/server/AyaNova/biz/CustomFieldsValidator.cs index 6018d1f8..92de86af 100644 --- a/server/AyaNova/biz/CustomFieldsValidator.cs +++ b/server/AyaNova/biz/CustomFieldsValidator.cs @@ -41,19 +41,25 @@ namespace AyaNova.Biz //here we have both a bunch of custom fields presumeably and a form customization so let's get cracking... //parse the custom fields, it should contain an object with 16 keys + //NOTE: to save bandwidth the actual custom fields look like this: + // - {c1:"blah",c2:"blah",c3:"blah".....c16:"blah"} + //However the LT field names might be WidgetCustom1 or UserCustom16 so we need to translate by EndsWith var CustomFieldData = JObject.Parse(customFields); //make sure all the keys are present foreach (string iFldKey in ThisFormCustomFieldsList) { - if (CustomFieldData.ContainsKey(iFldKey)) + + //Now translate the LT field key to the actual customFieldData field key + var InternalCustomFieldName=FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey); + if (CustomFieldData.ContainsKey(InternalCustomFieldName)) { //validate for now that the custom fields set as required have data in them. Note that we are not validating the sanity of the values, only that they exist //trying to build in slack for when users inevitably change the TYPE of the custom field //Maybe in future this will be handled more thoroughly here but for now just make sure it's been filled in //validate it - string CurrentValue = CustomFieldData[iFldKey].Value(); + string CurrentValue = CustomFieldData[InternalCustomFieldName].Value(); foreach (JObject jo in FormTemplate) { if (jo["fld"].Value() == iFldKey) diff --git a/server/AyaNova/biz/FormAvailableFields.cs b/server/AyaNova/biz/FormAvailableFields.cs index 25501ac4..ba346e5d 100644 --- a/server/AyaNova/biz/FormAvailableFields.cs +++ b/server/AyaNova/biz/FormAvailableFields.cs @@ -98,6 +98,13 @@ namespace AyaNova.Biz } + public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName) + { + var i = int.Parse(lTCustomFieldName); + return $"c{i}"; + } + + }//eoc FormAvailableFields @@ -117,7 +124,7 @@ namespace AyaNova.Biz PropertyName = propertyName; } - public FormField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false) + public FormField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false) { Key = key; Hideable = hideable; diff --git a/server/AyaNova/biz/RequiredFieldsValidator.cs b/server/AyaNova/biz/RequiredFieldsValidator.cs index d84d3eef..9c561257 100644 --- a/server/AyaNova/biz/RequiredFieldsValidator.cs +++ b/server/AyaNova/biz/RequiredFieldsValidator.cs @@ -23,20 +23,24 @@ namespace AyaNova.Biz { if (jo["required"].Value() == true) { - //get the actual property name //First get the LT key var FldLtKey = jo["fld"].Value(); - // - e.g.: {template:[{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"bool"},{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"text"]} + //get teh FormField object + FormField FF = FormFields.Where(x => x.Key == FldLtKey).Single(); + if (!string.IsNullOrWhiteSpace(FF.PropertyName)) + { + //Now get the actual property name from the available fields using the lt key + string RequiredPropertyName = FF.PropertyName; - string RequiredPropertyName = FormFields.Where(x => x.Key == FldLtKey).Single().PropertyName; + //use reflection to get the underlying value from the proposed object to be saved + object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null); + + if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString())) + biz.AddError(ValidationErrorType.RequiredPropertyEmpty, FldLtKey); + } - //use reflection to get the underlying value - object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null); - if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString())) - biz.AddError(ValidationErrorType.RequiredPropertyEmpty, FldLtKey); - break; } } }