diff --git a/server/AyaNova/biz/CustomFieldsValidator.cs b/server/AyaNova/biz/CustomFieldsValidator.cs index 7ec4f378..a114c907 100644 --- a/server/AyaNova/biz/CustomFieldsValidator.cs +++ b/server/AyaNova/biz/CustomFieldsValidator.cs @@ -9,12 +9,18 @@ namespace AyaNova.Biz { 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 if (formCustom == null) 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 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(); - //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(); - var fldRequired = FormTemplate[i]["required"].Value(); - //Check if this is an expected custom field and that it was set to required - //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); - } - } + //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 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(); + // var fldRequired = FormTemplate[i]["required"].Value(); + // //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... //parse the custom fields, it should contain an object with 16 keys @@ -62,8 +70,8 @@ namespace AyaNova.Biz //case 4615 //ensure descendant custom fields are only checked against matching descendant objects if (checkPrefix && !iFldKey.StartsWith(onlyIfStartsWith)) - continue; - //ensure when validating work order header don't check workorder item custom fields as both could be present here + continue; + //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")) continue; @@ -92,20 +100,6 @@ namespace AyaNova.Biz { biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey); } - - // foreach (JObject jo in FormTemplate) - // { - // if (jo["fld"].Value() == iFldKey) - // { - // var fldRequired = jo["required"].Value(); - // if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue)) - // { - // biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey); - // } - // break; - // } - // } - } else {