This commit is contained in:
@@ -23,7 +23,7 @@ Here are all the API level error codes that can be returned by the API server:
|
|||||||
| 2201 | Validation error - Field is required but is empty or null |
|
| 2201 | Validation error - Field is required but is empty or null |
|
||||||
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
|
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
|
||||||
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
|
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
|
||||||
| 2204 | Validation error - Customized form property set to required has an empty value |
|
| 2204 | Validation error - Customized form property is set to required but has an empty value |
|
||||||
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
|
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
|
||||||
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
|
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
|
||||||
| 2207 | Validation error - The start date must be earlier than the end date |
|
| 2207 | Validation error - The start date must be earlier than the end date |
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace AyaNova.Biz
|
|||||||
| 2201 | Validation error - Field is required but is empty or null |
|
| 2201 | Validation error - Field is required but is empty or null |
|
||||||
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
|
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |
|
||||||
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
|
| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) |
|
||||||
| 2204 | Validation error - Customized form property set to required has an empty value |
|
| 2204 | Validation error - Customized form property is set to required but has an empty value |
|
||||||
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
|
| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error |
|
||||||
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
|
| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database |
|
||||||
| 2207 | Validation error - When an object requires a start and end date the start date must be earlier than the end date |
|
| 2207 | Validation error - When an object requires a start and end date the start date must be earlier than the end date |
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace AyaNova.Biz
|
|||||||
case ApiErrorCode.VALIDATION_INVALID_VALUE:
|
case ApiErrorCode.VALIDATION_INVALID_VALUE:
|
||||||
return "Field is set to a non allowed value";
|
return "Field is set to a non allowed value";
|
||||||
case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY:
|
case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY:
|
||||||
return "Customized form property set to required has an empty value";
|
return "Customized form property is set to required but has an empty value";
|
||||||
case ApiErrorCode.VALIDATION_MISSING_PROPERTY:
|
case ApiErrorCode.VALIDATION_MISSING_PROPERTY:
|
||||||
return "Required property is missing entirel";
|
return "Required property is missing entirel";
|
||||||
case ApiErrorCode.VALIDATION_NOT_UNIQUE:
|
case ApiErrorCode.VALIDATION_NOT_UNIQUE:
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace AyaNova.Biz
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
var OuterJson=JObject.Parse(formCustom.Template);
|
var OuterJson = JObject.Parse(formCustom.Template);
|
||||||
//var FormTemplate = JArray.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();
|
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
|
//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
|
//However the LT field names might be WidgetCustom1 or UserCustom16 so we need to translate by EndsWith
|
||||||
var CustomFieldData = JObject.Parse(customFields);
|
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)
|
foreach (string iFldKey in ThisFormCustomFieldsList)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Now translate the LT field key to the actual customFieldData field key
|
//Translate the LT field key to the actual customFieldData field key
|
||||||
var InternalCustomFieldName=FormAvailableFields.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey);
|
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))
|
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
|
//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,19 +71,25 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//validate it
|
//validate it
|
||||||
string CurrentValue = CustomFieldData[InternalCustomFieldName].Value<string>();
|
string CurrentValue = CustomFieldData[InternalCustomFieldName].Value<string>();
|
||||||
foreach (JObject jo in FormTemplate)
|
|
||||||
|
if (string.IsNullOrWhiteSpace(CurrentValue))
|
||||||
{
|
{
|
||||||
if (jo["fld"].Value<string>() == iFldKey)
|
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
||||||
{
|
|
||||||
var fldRequired = jo["required"].Value<bool>();
|
|
||||||
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
|
||||||
{
|
|
||||||
biz.AddError(ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY, iFldKey);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
{
|
{
|
||||||
@@ -85,5 +100,23 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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
|
}//eoc
|
||||||
}//ens
|
}//ens
|
||||||
|
|||||||
@@ -527,18 +527,8 @@ namespace AyaNova.Util
|
|||||||
o.Notes = f.Lorem.Paragraph();
|
o.Notes = f.Lorem.Paragraph();
|
||||||
o.Tags = RandomTags(f);
|
o.Tags = RandomTags(f);
|
||||||
|
|
||||||
|
|
||||||
//RANDOM CUSTOM FIELD DATA
|
//RANDOM CUSTOM FIELD DATA
|
||||||
//var custDate=GetSomeDateHereThatIsThenMadeIntoText;
|
o.CustomFields=@"{c1:""2019-05-01T21:38:07Z"",c2:""Here is some custom field text in position 2"",c3:100,c4:true,c5:5.55}";
|
||||||
|
|
||||||
// Template = "{template:[{fld:\"WidgetNotes\",required:\"true\"}" +
|
|
||||||
// ",{fld:\"WidgetCustom1\",hide:\"false\",required:\"false\", type:\"date\"}" +
|
|
||||||
// ",{fld:\"WidgetCustom2\",hide:\"false\",required:\"true\", type:\"text\"}" +
|
|
||||||
// ",{fld:\"WidgetCustom3\",hide:\"false\",required:\"false\", type:\"int\"}" +
|
|
||||||
// ",{fld:\"WidgetCustom4\",hide:\"false\",required:\"false\", type:\"bool\"}" +
|
|
||||||
// ",{fld:\"WidgetCustom5\",hide:\"false\",required:\"false\", type:\"decimal\"}" +
|
|
||||||
// "]"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, o);
|
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, o);
|
||||||
|
|||||||
Reference in New Issue
Block a user