case 4615
This commit is contained in:
@@ -7,17 +7,22 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
internal static class CustomFieldsValidator
|
internal static class CustomFieldsValidator
|
||||||
{
|
{
|
||||||
internal static void Validate(BizObject biz, FormCustom formCustom, string customFields)
|
internal static void Validate(BizObject biz, FormCustom formCustom, string customFields, string onlyIfStartsWith = null)
|
||||||
{
|
{
|
||||||
bool hasCustomData = !string.IsNullOrWhiteSpace(customFields);
|
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;
|
||||||
|
|
||||||
var FormTemplate = JArray.Parse(formCustom.Template);
|
|
||||||
|
//case 4615
|
||||||
|
bool checkPrefix = !string.IsNullOrEmpty(onlyIfStartsWith);
|
||||||
|
|
||||||
|
var FormTemplate = JArray.Parse(formCustom.Template);
|
||||||
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 the customFields string is empty then only validation is if any of the fields are required to be filled in
|
||||||
if (!hasCustomData)
|
if (!hasCustomData)
|
||||||
{
|
{
|
||||||
@@ -28,6 +33,10 @@ namespace AyaNova.Biz
|
|||||||
var fldKey = FormTemplate[i]["fld"].Value<string>();
|
var fldKey = FormTemplate[i]["fld"].Value<string>();
|
||||||
var fldRequired = FormTemplate[i]["required"].Value<bool>();
|
var fldRequired = FormTemplate[i]["required"].Value<bool>();
|
||||||
//Check if this is an expected custom field and that it was set to required
|
//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)
|
if (ThisFormCustomFieldsList.Contains(fldKey) && fldRequired == true)
|
||||||
{
|
{
|
||||||
//Ok, this field is required but custom fields are all empty so add this error
|
//Ok, this field is required but custom fields are all empty so add this error
|
||||||
@@ -43,13 +52,21 @@ namespace AyaNova.Biz
|
|||||||
//NOTE: to save bandwidth the actual custom fields look like this:
|
//NOTE: to save bandwidth the actual custom fields look like this:
|
||||||
// - {c1:"blah",c2:"blah",c3:"blah".....c16:"blah"}
|
// - {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
|
//However the LT field names might be WidgetCustom1 or UserCustom16 so we need to translate by EndsWith
|
||||||
|
|
||||||
//Top level object is a Object not an array when it comes to custom fields and the key names are the custom fields abbreviated
|
//Top level object is a Object not an array when it comes to custom fields and the key names are the custom fields abbreviated
|
||||||
var CustomFieldData = JObject.Parse(customFields);
|
var CustomFieldData = JObject.Parse(customFields);
|
||||||
|
|
||||||
//make sure all the *required* keys are present
|
//make sure all the *required* keys are present
|
||||||
foreach (string iFldKey in ThisFormCustomFieldsList)
|
foreach (string iFldKey in ThisFormCustomFieldsList)
|
||||||
{
|
{
|
||||||
|
//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
|
||||||
|
if (!checkPrefix && iFldKey.StartsWith("WorkOrderItem"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
//Translate the LT field key to the actual customFieldData field key
|
//Translate the LT field key to the actual customFieldData field key
|
||||||
var InternalCustomFieldName = FormFieldOptionalCustomizableReference.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
|
var InternalCustomFieldName = FormFieldOptionalCustomizableReference.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
|
||||||
|
|||||||
@@ -1512,7 +1512,7 @@ namespace AyaNova.Biz
|
|||||||
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
||||||
|
|
||||||
//validate custom fields
|
//validate custom fields
|
||||||
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1748,7 +1748,7 @@ namespace AyaNova.Biz
|
|||||||
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
||||||
|
|
||||||
//validate custom fields
|
//validate custom fields
|
||||||
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2566,7 +2566,7 @@ namespace AyaNova.Biz
|
|||||||
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);//note: this is passed only to add errors
|
||||||
|
|
||||||
//validate custom fields
|
//validate custom fields
|
||||||
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields, "WorkOrderItem");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user