This commit is contained in:
2019-01-16 19:52:57 +00:00
parent d582c67c62
commit d19becea1b
3 changed files with 28 additions and 11 deletions

View File

@@ -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>();
string CurrentValue = CustomFieldData[InternalCustomFieldName].Value<string>();
foreach (JObject jo in FormTemplate)
{
if (jo["fld"].Value<string>() == iFldKey)

View File

@@ -98,6 +98,13 @@ namespace AyaNova.Biz
}
public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName)
{
var i = int.Parse(lTCustomFieldName);
return $"c{i}";
}
}//eoc FormAvailableFields

View File

@@ -23,20 +23,24 @@ namespace AyaNova.Biz
{
if (jo["required"].Value<bool>() == true)
{
//get the actual property name
//First get the LT key
var FldLtKey = jo["fld"].Value<string>();
// - 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
//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);
break;
}
}
}
}