Amol Pawar
Amol Pawar

Reputation: 251

Customize/modifiy prompt text of a class property in bot framework

I have below field in my class

[Prompt("Please enter conference title/subject")]
public string confname { get; set; }

I want to modify text "Please enter conference title/subject" dynamically. Actually, I want to pass URL along with prompt text, how to achieve this?

I have tried below code, but don't know how to pass modified text in promptattribute

public static IForm<ConferenceBooking> BuildForm()
{
     return new FormBuilder<ConferenceBooking>().Message("Tell me meeting details!")
     .Field(nameof(confname), prompt: new PromptAttribute("please enter confname"))
}

Upvotes: 0

Views: 311

Answers (1)

Xeno-D
Xeno-D

Reputation: 2213

You can use the SetDefine(delegate) to dynamically change the attributes of a field. The delegate has two parameters: the state of the form and the field it's binded too. The delegate should always return true.

Here is an example:

[Serializable]
public class SimpleForm
{
    public string Name;

    [Numeric(1, 5)]
    [Prompt("Your experience with the form")]
    public float? Rating;

    public static IForm<SimpleForm> BuildForm()
    {
        return new FormBuilder<SimpleForm>()
                .Field(nameof(Rating))
                .Field(new FieldReflector<SimpleForm>(nameof(Name))
                    .SetDefine(DefinitionMethod))
                .Build();
    }

    private static async Task<bool> DefinitionMethod(SimpleForm state, Field<SimpleForm> field)
    {
        field.SetPrompt(new PromptAttribute($"You chose a rating of {state.Rating}. What is your name?."));
        return true;
    }
}

Upvotes: 1

Related Questions