-
Notifications
You must be signed in to change notification settings - Fork 321
expand validationFunction #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| // <validationFunction> | ||
| .Field(nameof(Toppings), | ||
| validate: async (state, value) => | ||
| { | ||
| var values = ((List<object>)value).OfType<ToppingOptions>(); | ||
| var result = new ValidateResult { IsValid = true, Value = values }; | ||
| if (values != null && values.Contains(ToppingOptions.Everything)) | ||
| { | ||
| result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions)) | ||
| where topping != ToppingOptions.Everything && !values.Contains(topping) | ||
| select topping).ToList(); | ||
| } | ||
| return result; | ||
| }) | ||
| public static IForm<SandwichOrder> BuildForm() | ||
| { | ||
| ... | ||
| return new FormBuilder<SandwichOrder>() | ||
| .Message("Welcome to the sandwich order bot!") | ||
| ... | ||
| .Field(nameof(Toppings), | ||
| validate: async (state, value) => | ||
| { | ||
| var values = ((List<object>)value).OfType<ToppingOptions>(); | ||
| var result = new ValidateResult { IsValid = true, Value = values }; | ||
| if (values != null && values.Contains(ToppingOptions.Everything)) | ||
| { | ||
| result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions)) | ||
| where topping != ToppingOptions.Everything && !values.Contains(topping) | ||
| select topping).ToList(); | ||
| } | ||
| return result; | ||
| }) | ||
|
||
| .Message("For sandwich toppings you have selected {Toppings}.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the line .Message("For sandwich toppings you have selected {Toppings}."), please add these 3 lines: Four your reference (re proper indentation), here's what all four of those lines should look like together: |
||
| .Message("For sandwich toppings you have selected {Toppings}.") | ||
|
||
| // </validationFunction> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the "..." here and instead add these four lines that precede the Toppings line in the sample app:
.Field(nameof(Sandwich))
.Field(nameof(Length))
.Field(nameof(Bread))
.Field(nameof(Cheese))