public override IFormBuilder <T> Field(string name, PromptAttribute prompt, ActiveDelegate <T> active = null, ValidateAsyncDelegate <T> validate = null) { var field = new FieldReflector <T>(name, _ignoreAnnotations); field.SetActive(active); field.SetValidate(validate); field.SetPrompt(prompt); return(Field(field)); }
public IFormBuilder <T> Field(string name, PromptAttribute prompt, ConditionalDelegate <T> condition = null, ValidateDelegate <T> validate = null) { var field = (condition == null ? new FieldReflector <T>(name) : new Conditional <T>(name, condition)); if (validate != null) { field.SetValidation(validate); } field.SetPrompt(prompt); return(AddField(field)); }
public virtual IFormBuilder <T> Confirm(PromptAttribute prompt, ActiveDelegate <T> condition = null, IEnumerable <string> dependencies = null) { if (condition == null) { condition = state => true; } dependencies = dependencies ?? _form.Dependencies(_form.Steps.Count()); var confirmation = new Confirmation <T>(prompt, condition, dependencies, _form); confirmation.Form = _form; _form._fields.Add(confirmation); _form._steps.Add(new ConfirmStep <T>(confirmation)); return(this); }
public IFormBuilder <T> Confirm(PromptAttribute prompt, ConditionalDelegate <T> condition = null, IEnumerable <string> dependencies = null) { if (condition == null) { condition = state => true; } if (dependencies == null) { // Default next steps go from previous field ignoring confirmations back to next confirmation // Last field before confirmation var end = _form._steps.Count(); while (end > 0) { if (_form._steps[end - 1].Type == StepType.Field) { break; } --end; } var start = end; while (start > 0) { if (_form._steps[start - 1].Type == StepType.Confirm) { break; } --start; } var fields = new List <string>(); for (var i = start; i < end; ++i) { if (_form._steps[i].Type == StepType.Field) { fields.Add(_form._steps[i].Name); } } dependencies = fields; } var confirmation = new Confirmation <T>(prompt, condition, dependencies); confirmation.Form = _form; _form._fields.Add(confirmation); _form._steps.Add(new ConfirmStep <T>(confirmation)); return(this); }
public abstract IFormBuilder <T> Field(string name, PromptAttribute prompt, ActiveDelegate <T> active = null, ValidateAsyncDelegate <T> validate = null);
public virtual IFormBuilder <T> Message(PromptAttribute prompt, ActiveDelegate <T> condition = null, IEnumerable <string> dependencies = null) { _form._steps.Add(new MessageStep <T>(prompt, condition, dependencies, _form)); return(this); }
/// <summary> /// Define a step for filling in a particular value in a JObject as defined by a JSON Schema. /// </summary> /// <param name="builder">Form builder.</param> /// <param name="schema">JSON schema defining JObject.</param> /// <param name="name">Path in the form state to the value being filled in.</param> /// <param name="prompt">Prompt pattern with more formatting control to describe prompt for field.</param> /// <param name="active">Delegate to test form state to see if step is active.n</param> /// <param name="validate">Delegate to validate the field value.</param> /// <returns>This form.</returns> /// <remarks> /// See <see cref="FieldJson"/> for a description of JSON Schema extensions /// for defining your fields. /// </remarks> public static IFormBuilder <JObject> Field(this IFormBuilder <JObject> builder, JObject schema, string name, PromptAttribute prompt, ActiveDelegate <JObject> active = null, ValidateAsyncDelegate <JObject> validate = null) { var field = new FieldJson(schema, name); field.SetPrompt(prompt); if (active != null) { field.SetActive(active); } if (validate != null) { field.SetValidate(validate); } return(builder.Field(field)); }
/// <summary> /// Define a step for filling in a particular value in the form state. /// </summary> /// <param name="builder">Form builder.</param> /// <param name="name">Path in the form state to the value being filled in.</param> /// <param name="prompt">Prompt pattern with more formatting control to describe prompt for field.</param> /// <param name="active">Delegate to test form state to see if step is active.n</param> /// <param name="validate">Delegate to validate the field value.</param> /// <returns>This form.</returns> /// <remarks> /// This step will use reflection to construct everything needed for a dialog from a combination /// of the <see cref="DescribeAttribute"/>, <see cref="TermsAttribute"/>, <see cref="PromptAttribute"/>, <see cref="OptionalAttribute"/> /// <see cref="NumericAttribute"/> and <see cref="TemplateAttribute"/> annotations that are supplied by default or you /// override. /// </remarks> public static IFormBuilder <T> Field <T>(this IFormBuilder <T> builder, string name, PromptAttribute prompt, ActiveDelegate <T> active = null, ValidateAsyncDelegate <T> validate = null) where T : class { var field = (active == null ? new FieldReflector <T>(name) : new Conditional <T>(name, active)); if (validate != null) { field.SetValidate(validate); } field.SetPrompt(prompt); return(builder.Field(field)); }
public IFormBuilder <T> Message(PromptAttribute prompt, ConditionalDelegate <T> condition = null) { _form._steps.Add(new MessageStep <T>(prompt, condition, _form)); return(this); }