This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user