This commit is contained in:
@@ -17,7 +17,6 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
var FormTemplate = JArray.Parse(formCustom.Template);
|
||||
|
||||
var ThisFormCustomFieldsList = FormAvailableFields.FormFields(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList();
|
||||
|
||||
//If the customFields string is empty then only validation is if any of the fields are required to be filled in
|
||||
@@ -27,8 +26,8 @@ namespace AyaNova.Biz
|
||||
for (int i = 0; i < FormTemplate.Count; i++)
|
||||
{
|
||||
//get the field customization
|
||||
var fldKey = FormTemplate["fld"].Value<string>();
|
||||
var fldRequired = FormTemplate["required"].Value<bool>();
|
||||
var fldKey = FormTemplate[i]["fld"].Value<string>();
|
||||
var fldRequired = FormTemplate[i]["required"].Value<bool>();
|
||||
//Check if this is an expected custom field and that it was set to required
|
||||
if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
|
||||
{
|
||||
@@ -41,10 +40,42 @@ 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
|
||||
var CustomFieldData = JObject.Parse(customFields);
|
||||
|
||||
//make sure all the keys are present
|
||||
foreach (string iFldKey in ThisFormCustomFieldsList)
|
||||
{
|
||||
if (CustomFieldData.ContainsKey(iFldKey))
|
||||
{
|
||||
//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>();
|
||||
foreach (JObject jo in FormTemplate)
|
||||
{
|
||||
if (jo["fld"].Value<string>() == iFldKey)
|
||||
{
|
||||
var fldRequired = jo["required"].Value<bool>();
|
||||
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
||||
{
|
||||
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, iFldKey);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//This is a serious issue and invalidates all
|
||||
biz.AddError(ValidationErrorType.RequiredPropertyMissing, iFldKey);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}//eoc
|
||||
}//ens
|
||||
|
||||
Reference in New Issue
Block a user