Validating selection field

55 Views Asked by At

I have a property that has an enumeration, in one of the values of the enumeration I have "help", if the user selects that option, I would like to do two things: 1. Send the user a text with help. 2. Ask the user if he wants to continue, or if he wants to leave. I do not know how to do it. thank you very much.

public enum ContentClassification
{
    Confidential_Restricted = 1 ,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

public ContentClassification ContentClassification { get; set; }

return new FormBuilder() .Field(nameof(ContentClassification))

1

There are 1 best solutions below

0
On BEST ANSWER

You may launch the Form many times, means if you get the "Help" choice from the first Form, launch another form for confirmation.

For example:

public enum ContentClassification
{
    Confidential_Restricted = 1,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

public enum Validating
{
    Continue,
    Leave
};

[Serializable]
public class Classification
{
    public ContentClassification? Choice;

    public static IForm<Classification> BuildForm()
    {
        return new FormBuilder<Classification>()
            .Message("You want to")
            .Field(nameof(Choice))
            .Build();
    }

    public Validating? Confirmation;

    public static IForm<Classification> BuildConfirmForm()
    {
        return new FormBuilder<Classification>()
            .Message("Send your message here")
            .Field(nameof(Confirmation))
            .Build();
    }
}

And then create your RootDialog for example like this:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        var form = new FormDialog<Classification>(new Classification(), Classification.BuildForm, FormOptions.PromptInStart, null);
        context.Call(form, this.GetResultAsync);

        return Task.CompletedTask;
    }


    private async Task GetResultAsync(IDialogContext context, IAwaitable<Classification> result)
    {
        var state = await result;
        if (state.Choice == ContentClassification.help)
        {
            var form = new FormDialog<Classification>(new Classification(), Classification.BuildConfirmForm, FormOptions.PromptInStart, null);
            context.Call(form, null); //change null to your result task here to handle the result.
        }
    }
}

You still need to implement the logic codes for other options in GetResultAsync method together with the logic codes to handle the result of second form BuildConfirmForm.