public DropdownFieldBuilder(FieldBuilder <TProperty, TEntity> parent, DataField field) { _field = field; _parent = parent; }
private void CustomRule(IDataForm form, IEnumerable <DataField> fields, object item, int rowIndex, DataField field, List <ValidationResult> result, FormRuleTriggers trigger) { var rules = field.Rules.Where(r => r.Trigger == trigger || (trigger == FormRuleTriggers.ChangeSubmit && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit)) || (trigger == FormRuleTriggers.Submit && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit || r.Trigger == FormRuleTriggers.ChangeSubmit)) || (trigger == FormRuleTriggers.Change && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit || r.Trigger == FormRuleTriggers.ChangeSubmit)) ); foreach (var rule in rules) { FormRuleResult vr; if (rule.Method != null) { vr = rule.Method(item); } else { Type argsType = typeof(RuleArgs <>).MakeGenericType(rule.EntityType); var args = Activator.CreateInstance(argsType, item) as RuleArgs; vr = rule.MethodArgs(args); var ruleFields = args.EntityBuilder.GetFieldDictionary(); //ToDo: update fields appearance here foreach (var f in fields) { var rf = ruleFields[f.BindingProperty]; f.Required = rf.Required; f.Hidden = rf.Hidden; f.ReadOnly = rf.ReadOnly; f.Label = rf.Label; } } if (vr != null && vr.IsFailed) { result.Add(new ValidationResult { Message = $"{vr.RuleName}: {vr.Message}", BindingProperty = field.BindingProperty, ValidationResultType = ValidationResultTypes.Error, RowIndex = rowIndex }); } } }