This commit is contained in:
@@ -9,12 +9,18 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
internal static void Validate(BizObject biz, FormCustom formCustom, string customFields, string onlyIfStartsWith = null)
|
internal static void Validate(BizObject biz, FormCustom formCustom, string customFields, string onlyIfStartsWith = null)
|
||||||
{
|
{
|
||||||
bool hasCustomData = !string.IsNullOrWhiteSpace(customFields);
|
|
||||||
|
|
||||||
//No form custom = no template to check against so nothing to do
|
//No form custom = no template to check against so nothing to do
|
||||||
if (formCustom == null)
|
if (formCustom == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//case 4615
|
||||||
|
//this is to eliminate the old block optimization to short circuit checking if there is no custom data present
|
||||||
|
if (string.IsNullOrWhiteSpace(customFields))
|
||||||
|
{
|
||||||
|
customFields = "{}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//case 4615
|
//case 4615
|
||||||
bool checkPrefix = !string.IsNullOrEmpty(onlyIfStartsWith);
|
bool checkPrefix = !string.IsNullOrEmpty(onlyIfStartsWith);
|
||||||
@@ -23,29 +29,31 @@ namespace AyaNova.Biz
|
|||||||
var ThisFormCustomFieldsList = FormFieldOptionalCustomizableReference.FormFieldReferenceList(formCustom.FormKey).Where(z => z.IsCustomField == true).Select(z => z.TKey).ToList();
|
var ThisFormCustomFieldsList = FormFieldOptionalCustomizableReference.FormFieldReferenceList(formCustom.FormKey).Where(z => z.IsCustomField == true).Select(z => z.TKey).ToList();
|
||||||
|
|
||||||
|
|
||||||
//If the customFields string is empty then only validation is if any of the fields are required to be filled in
|
|
||||||
if (!hasCustomData)
|
|
||||||
{
|
|
||||||
//iterate the template
|
|
||||||
for (int i = 0; i < FormTemplate.Count; i++)
|
|
||||||
{
|
|
||||||
//get the field customization
|
|
||||||
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
|
|
||||||
|
|
||||||
//case 4615
|
//case 4615 moved this logic into main check below as it would not support startsWith and isn't much of an optimization anyway; less code is best code.
|
||||||
if (checkPrefix)
|
// //If the customFields string is empty then only validation is if any of the fields are required to be filled in
|
||||||
continue;
|
// if (!hasCustomData)
|
||||||
if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
|
// {
|
||||||
{
|
// //iterate the template
|
||||||
//Ok, this field is required but custom fields are all empty so add this error
|
// for (int i = 0; i < FormTemplate.Count; i++)
|
||||||
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, fldKey);
|
// {
|
||||||
}
|
// //get the field customization
|
||||||
}
|
// 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
|
||||||
|
|
||||||
return;
|
// //case 4615
|
||||||
}
|
// if (checkPrefix)
|
||||||
|
// continue;
|
||||||
|
// if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
|
||||||
|
// {
|
||||||
|
// //Ok, this field is required but custom fields are all empty so add this error
|
||||||
|
// biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, fldKey);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
//here we have both a bunch of custom fields presumeably and a form customization so let's get cracking...
|
//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
|
//parse the custom fields, it should contain an object with 16 keys
|
||||||
@@ -62,8 +70,8 @@ namespace AyaNova.Biz
|
|||||||
//case 4615
|
//case 4615
|
||||||
//ensure descendant custom fields are only checked against matching descendant objects
|
//ensure descendant custom fields are only checked against matching descendant objects
|
||||||
if (checkPrefix && !iFldKey.StartsWith(onlyIfStartsWith))
|
if (checkPrefix && !iFldKey.StartsWith(onlyIfStartsWith))
|
||||||
continue;
|
continue;
|
||||||
//ensure when validating work order header don't check workorder item custom fields as both could be present here
|
//ensure when validating work order header don't check workorder item (or workorderitemunit, both work here) custom fields as both could be present here
|
||||||
if (!checkPrefix && iFldKey.StartsWith("WorkOrderItem"))
|
if (!checkPrefix && iFldKey.StartsWith("WorkOrderItem"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -92,20 +100,6 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user