This commit is contained in:
@@ -5,7 +5,8 @@ In each case there may be more details in the `message` property where appropria
|
|||||||
|
|
||||||
| CODE | MEANING |
|
| CODE | MEANING |
|
||||||
| ----- | ------------------------------ |
|
| ----- | ------------------------------ |
|
||||||
| RequiredPropertyEmpty | Required property value is empty |
|
| RequiredPropertyEmpty | An AyaNova fixed rule required property value is empty |
|
||||||
|
| CustomRequiredPropertyEmpty | A user customized form property set to required has an empty value |
|
||||||
| RequiredPropertyMissing | Required property is missing entirely |
|
| RequiredPropertyMissing | Required property is missing entirely |
|
||||||
| LengthExceeded | A text property has more characters than are allowed. The limit will be returned in the `message` property of the validation error |
|
| LengthExceeded | A text property has more characters than are allowed. The limit will be returned in the `message` property of the validation error |
|
||||||
| NotUnique | A text property is required to be unique but an existing identical value was found in the database |
|
| NotUnique | A text property is required to be unique but an existing identical value was found in the database |
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace AyaNova.Biz
|
|||||||
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
|
||||||
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, fldKey);
|
biz.AddError(ValidationErrorType.CustomRequiredPropertyEmpty, fldKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ namespace AyaNova.Biz
|
|||||||
var fldRequired = jo["required"].Value<bool>();
|
var fldRequired = jo["required"].Value<bool>();
|
||||||
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
if (fldRequired && string.IsNullOrWhiteSpace(CurrentValue))
|
||||||
{
|
{
|
||||||
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, iFldKey);
|
biz.AddError(ValidationErrorType.CustomRequiredPropertyEmpty, iFldKey);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,16 +32,16 @@ namespace AyaNova.Biz
|
|||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case WIDGET_FORM_KEY:
|
case WIDGET_FORM_KEY:
|
||||||
l.Add(new FormField("WidgetName", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget
|
l.Add(new FormField("WidgetName", "Name", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget
|
||||||
l.Add(new FormField("WidgetSerial"));//not in validation rules...you get the idea
|
l.Add(new FormField("WidgetSerial", "Serial"));//not in validation rules...you get the idea
|
||||||
l.Add(new FormField("WidgetDollarAmount"));
|
l.Add(new FormField("WidgetDollarAmount", "DollarAmount"));
|
||||||
l.Add(new FormField("WidgetCount"));
|
l.Add(new FormField("WidgetCount", "Count"));
|
||||||
l.Add(new FormField("WidgetRoles"));
|
l.Add(new FormField("WidgetRoles", "Roles"));
|
||||||
l.Add(new FormField("WidgetStartDate", false, false));
|
l.Add(new FormField("WidgetStartDate", "StartDate", false, false));
|
||||||
l.Add(new FormField("WidgetEndDate", false, false));
|
l.Add(new FormField("WidgetEndDate", "EndDate", false, false));
|
||||||
l.Add(new FormField("WidgetNotes"));
|
l.Add(new FormField("WidgetNotes", "Notes"));
|
||||||
l.Add(new FormField("CommonActive", true));
|
l.Add(new FormField("CommonActive", "Active", true));
|
||||||
l.Add(new FormField("Tags", true));
|
l.Add(new FormField("Tags", "Tags", true));
|
||||||
l.Add(new FormField("WidgetCustom1", false, true, true));
|
l.Add(new FormField("WidgetCustom1", false, true, true));
|
||||||
l.Add(new FormField("WidgetCustom2", false, true, true));
|
l.Add(new FormField("WidgetCustom2", false, true, true));
|
||||||
l.Add(new FormField("WidgetCustom3", false, true, true));
|
l.Add(new FormField("WidgetCustom3", false, true, true));
|
||||||
@@ -60,34 +60,34 @@ namespace AyaNova.Biz
|
|||||||
l.Add(new FormField("WidgetCustom16", false, true, true));
|
l.Add(new FormField("WidgetCustom16", false, true, true));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case USER_FORM_KEY:
|
// case USER_FORM_KEY:
|
||||||
// l.Add(new FormField("WidgetName", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget
|
// l.Add(new FormField("WidgetName", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget
|
||||||
// l.Add(new FormField("WidgetSerial"));//not in validation rules...you get the idea
|
// l.Add(new FormField("WidgetSerial"));//not in validation rules...you get the idea
|
||||||
// l.Add(new FormField("WidgetDollarAmount"));
|
// l.Add(new FormField("WidgetDollarAmount"));
|
||||||
// l.Add(new FormField("WidgetCount"));
|
// l.Add(new FormField("WidgetCount"));
|
||||||
// l.Add(new FormField("WidgetRoles"));
|
// l.Add(new FormField("WidgetRoles"));
|
||||||
// l.Add(new FormField("WidgetStartDate", false, false));
|
// l.Add(new FormField("WidgetStartDate", false, false));
|
||||||
// l.Add(new FormField("WidgetEndDate", false, false));
|
// l.Add(new FormField("WidgetEndDate", false, false));
|
||||||
// l.Add(new FormField("WidgetNotes"));
|
// l.Add(new FormField("WidgetNotes"));
|
||||||
// l.Add(new FormField("CommonActive", true));
|
// l.Add(new FormField("CommonActive", true));
|
||||||
// l.Add(new FormField("Tags", true));
|
// l.Add(new FormField("Tags", true));
|
||||||
// l.Add(new FormField("WidgetCustom1", false, true, true));
|
// l.Add(new FormField("WidgetCustom1", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom2", false, true, true));
|
// l.Add(new FormField("WidgetCustom2", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom3", false, true, true));
|
// l.Add(new FormField("WidgetCustom3", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom4", false, true, true));
|
// l.Add(new FormField("WidgetCustom4", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom5", false, true, true));
|
// l.Add(new FormField("WidgetCustom5", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom6", false, true, true));
|
// l.Add(new FormField("WidgetCustom6", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom7", false, true, true));
|
// l.Add(new FormField("WidgetCustom7", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom8", false, true, true));
|
// l.Add(new FormField("WidgetCustom8", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom9", false, true, true));
|
// l.Add(new FormField("WidgetCustom9", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom10", false, true, true));
|
// l.Add(new FormField("WidgetCustom10", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom11", false, true, true));
|
// l.Add(new FormField("WidgetCustom11", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom12", false, true, true));
|
// l.Add(new FormField("WidgetCustom12", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom13", false, true, true));
|
// l.Add(new FormField("WidgetCustom13", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom14", false, true, true));
|
// l.Add(new FormField("WidgetCustom14", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom15", false, true, true));
|
// l.Add(new FormField("WidgetCustom15", false, true, true));
|
||||||
// l.Add(new FormField("WidgetCustom16", false, true, true));
|
// l.Add(new FormField("WidgetCustom16", false, true, true));
|
||||||
// break;
|
// break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -104,15 +104,26 @@ namespace AyaNova.Biz
|
|||||||
public class FormField
|
public class FormField
|
||||||
{
|
{
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
public string PropertyName { get; set; }
|
||||||
public bool Hideable { get; set; }
|
public bool Hideable { get; set; }
|
||||||
public bool SharedLTKey { get; set; }
|
public bool SharedLTKey { get; set; }
|
||||||
public bool Custom { get; set; }
|
public bool Custom { get; set; }
|
||||||
public FormField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
public FormField(string key, string propertyName, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
Hideable = hideable;
|
Hideable = hideable;
|
||||||
Custom = custom;
|
Custom = custom;
|
||||||
SharedLTKey = sharedLTKey;
|
SharedLTKey = sharedLTKey;
|
||||||
|
PropertyName = propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
||||||
|
{
|
||||||
|
Key = key;
|
||||||
|
Hideable = hideable;
|
||||||
|
Custom = custom;
|
||||||
|
SharedLTKey = sharedLTKey;
|
||||||
|
PropertyName = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
server/AyaNova/biz/RequiredFieldsValidator.cs
Normal file
45
server/AyaNova/biz/RequiredFieldsValidator.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using AyaNova.Models;
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AyaNova.Biz
|
||||||
|
{
|
||||||
|
//VALIDATE REQUIRED FIELDS THAT ARE NOT CUSTOM
|
||||||
|
|
||||||
|
internal static class RequiredFieldsValidator
|
||||||
|
{
|
||||||
|
internal static void Validate(BizObject biz, FormCustom formCustom, object proposedObject)
|
||||||
|
{
|
||||||
|
//No form custom = no template to check against so nothing to do
|
||||||
|
if (formCustom == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var FormTemplate = JArray.Parse(formCustom.Template);
|
||||||
|
var FormFields = FormAvailableFields.FormFields(formCustom.FormKey);
|
||||||
|
// var ThisFormNormalFieldsList = FormFields.Where(x => x.Custom == false).Select(x => x.Key).ToList();
|
||||||
|
|
||||||
|
foreach (JObject jo in FormTemplate)
|
||||||
|
{
|
||||||
|
if (jo["required"].Value<bool>() == true)
|
||||||
|
{
|
||||||
|
//get the actual property name
|
||||||
|
//First get the LT key
|
||||||
|
var FldLtKey = jo["fld"].Value<string>();
|
||||||
|
|
||||||
|
// - e.g.: {template:[{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"bool"},{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"text"]}
|
||||||
|
|
||||||
|
|
||||||
|
string RequiredPropertyName = FormFields.Where(x => x.Key == FldLtKey).Single().PropertyName;
|
||||||
|
|
||||||
|
//use reflection to get the underlying value
|
||||||
|
object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null);
|
||||||
|
if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString()))
|
||||||
|
biz.AddError(ValidationErrorType.RequiredPropertyEmpty, FldLtKey);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
}//ens
|
||||||
@@ -11,7 +11,8 @@ namespace AyaNova.Biz
|
|||||||
ReferentialIntegrity = 6,
|
ReferentialIntegrity = 6,
|
||||||
InvalidOperation = 7,
|
InvalidOperation = 7,
|
||||||
NotChangeable=8,
|
NotChangeable=8,
|
||||||
RequiredPropertyMissing = 9
|
RequiredPropertyMissing = 9,
|
||||||
|
CustomRequiredPropertyEmpty = 10
|
||||||
|
|
||||||
//!! NOTE - UPDATE api-validation-error-codes.md documentation when adding items
|
//!! NOTE - UPDATE api-validation-error-codes.md documentation when adding items
|
||||||
|
|
||||||
|
|||||||
@@ -406,6 +406,7 @@ namespace AyaNova.Biz
|
|||||||
//Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
|
//Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
|
||||||
|
|
||||||
//validate users choices for required non custom fields
|
//validate users choices for required non custom fields
|
||||||
|
RequiredFieldsValidator.Validate(this,FormCustomization, proposedObj);
|
||||||
|
|
||||||
//validate custom fields
|
//validate custom fields
|
||||||
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
||||||
|
|||||||
Reference in New Issue
Block a user