This commit is contained in:
@@ -16,9 +16,9 @@ namespace AyaNova.Biz
|
||||
return;
|
||||
|
||||
|
||||
var OuterJson=JObject.Parse(formCustom.Template);
|
||||
var OuterJson = JObject.Parse(formCustom.Template);
|
||||
//var FormTemplate = JArray.Parse(formCustom.Template);
|
||||
var FormTemplate=(JArray)OuterJson["template"];
|
||||
var FormTemplate = (JArray)OuterJson["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
|
||||
@@ -48,12 +48,21 @@ namespace AyaNova.Biz
|
||||
//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
|
||||
//make sure all the *required* keys are present
|
||||
foreach (string iFldKey in ThisFormCustomFieldsList)
|
||||
{
|
||||
|
||||
//Now translate the LT field key to the actual customFieldData field key
|
||||
var InternalCustomFieldName=FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
|
||||
//Translate the LT field key to the actual customFieldData field key
|
||||
var InternalCustomFieldName = FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
|
||||
//Check if it's set to required
|
||||
var isRequired = CustomFieldIsSetToRequired(FormTemplate, iFldKey);
|
||||
|
||||
//if it's not required then we don't care, jump to the next item...
|
||||
if (!isRequired)
|
||||
continue;
|
||||
|
||||
//It's required, make sure the key is present and contains data
|
||||
|
||||
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
|
||||
@@ -62,28 +71,52 @@ namespace AyaNova.Biz
|
||||
|
||||
//validate it
|
||||
string CurrentValue = CustomFieldData[InternalCustomFieldName].Value<string>();
|
||||
foreach (JObject jo in FormTemplate)
|
||||
|
||||
if (string.IsNullOrWhiteSpace(CurrentValue))
|
||||
{
|
||||
if (jo["fld"].Value<string>() == iFldKey)
|
||||
{
|
||||
var fldRequired = jo["required"].Value<bool>();
|
||||
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
||||
{
|
||||
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
||||
}
|
||||
break;
|
||||
}
|
||||
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
||||
}
|
||||
|
||||
// foreach (JObject jo in FormTemplate)
|
||||
// {
|
||||
// if (jo["fld"].Value<string>() == iFldKey)
|
||||
// {
|
||||
// var fldRequired = jo["required"].Value<bool>();
|
||||
// if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
||||
// {
|
||||
// biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//This is a serious issue and invalidates all
|
||||
//This is a serious issue and invalidates all
|
||||
biz.AddError(ApiErrorCode.VALIDATION_MISSING_PROPERTY, iFldKey);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if field is required
|
||||
/// </summary>
|
||||
/// <param name="FormTemplate"></param>
|
||||
/// <param name="FieldKey"></param>
|
||||
/// <returns></returns>
|
||||
private static bool CustomFieldIsSetToRequired(JArray FormTemplate, string FieldKey)
|
||||
{
|
||||
foreach (JObject jo in FormTemplate)
|
||||
{
|
||||
if (jo["fld"].Value<string>() == FieldKey)
|
||||
{
|
||||
return jo["required"].Value<bool>();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
|
||||
Reference in New Issue
Block a user