From ee6e0adf7cd5873c2ca886ec85556d3e8d5656fc Mon Sep 17 00:00:00 2001 From: Misha133 <61027276+Misha-133@users.noreply.github.com> Date: Mon, 1 Aug 2022 14:23:43 +0300 Subject: [PATCH] Add RequiredInput to example modal (#2348) - Misha-133 --- docs/guides/int_framework/samples/intro/modal.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/guides/int_framework/samples/intro/modal.cs b/docs/guides/int_framework/samples/intro/modal.cs index 65cc81abf..8a6ba9d8a 100644 --- a/docs/guides/int_framework/samples/intro/modal.cs +++ b/docs/guides/int_framework/samples/intro/modal.cs @@ -12,7 +12,9 @@ public class FoodModal : IModal [ModalTextInput("food_name", placeholder: "Pizza", maxLength: 20)] public string Food { get; set; } - // Additional paremeters can be specified to further customize the input. + // Additional paremeters can be specified to further customize the input. + // Parameters can be optional + [RequiredInput(false)] [InputLabel("Why??")] [ModalTextInput("food_reason", TextInputStyle.Paragraph, "Kuz it's tasty", maxLength: 500)] public string Reason { get; set; } @@ -22,10 +24,15 @@ public class FoodModal : IModal [ModalInteraction("food_menu")] public async Task ModalResponse(FoodModal modal) { + // Check if "Why??" field is populated + string reason = string.IsNullOrWhiteSpace(modal.Reason) + ? "." + : $" because {modal.Reason}"; + // Build the message to send. string message = "hey @everyone, I just learned " + $"{Context.User.Mention}'s favorite food is " + - $"{modal.Food} because {modal.Reason}."; + $"{modal.Food}{reason}"; // Specify the AllowedMentions so we don't actually ping everyone. AllowedMentions mentions = new();