Jason Evans
Jason Evans

Reputation: 29186

Formflow bot confused with enum answer position vs answer text

I have a formflow dialog that has the following question defined as an enum

public enum PreviousOwnerOptions
{
    [Describe("Owned from new")]
    [Terms("0", "new", ".*[O|o]wned from new")]
    OwnedFromNew = 0,

    [Terms("1", "One")]
    One,

    [Terms("2", "Two")]
    Two,

    [Terms("3", "Three")]
    Three,

    [Terms("4", "Four")]
    Four,

    [Terms("5", "Five")]
    Five,

    [Terms("6", "Six")]
    Six,

    [Describe("More than six")]
    [Terms(".*More than six", "more")]
    MoreThanSix
}

Here is how the question appears to the user...

enter image description here

The problem I have is that if you enter, say, the number "3" as an answer, then the response is this...

enter image description here

It looks like the bot is not sure whether I meant the answer in position 3, or the answer "Three". I thought the Terms attribute would take care of that clarification?

How can I fix this please?

Upvotes: 3

Views: 137

Answers (1)

Zeryth
Zeryth

Reputation: 1204

This is happening because of a combination of 2 things.

First, you are trying to use the 0 Enum values on what appears to be a non-nullable field. The 0 value is reserved for null in this case. From the formflow docs page:

Any of the data types may be nullable, which you can use to model that the field does not have a value. If a form field is based on an enumeration property that is not nullable, the value 0 in the enumeration represents null (i.e., indicates that the field does not have a value), and you should start your enumeration values at 1. FormFlow ignores all other property types and methods.

The second piece of this is that since you are using the numerical values of 1,2,3 etc in your Terms attribute like [Terms("1", "One")] by default formflow will try to align these values with the correct enumeration. So what I think is happening is that it is letting you select "3" as you used in your example and since 3 is one of your terms [Terms("3", "Three")] it offeres you that options. but in the zero index enumeration values since 0 is reserved, the actual enumeration value of [Terms("2", "Two")] Two, is 3. So it doesn't know which you mean.

So in order to get this to work using these terms would be like this:

    public enum PreviousOwnerOptions
    {
        [Terms("1", "One")]
        One=1,

        [Terms("2", "Two")]
        Two,

        [Terms("3", "Three")]
        Three,

        [Terms("4", "Four")]
        Four,

        [Terms("5", "Five")]
        Five,

        [Terms("6", "Six")]
        Six,

        [Describe("More than six")]
        [Terms(".*More than six", "more")]
        MoreThanSix,

        [Describe("Owned from new")]
        [Terms("new", ".*[O|o]wned from new")]
        OwnedFromNew
    }

Upvotes: 11

Related Questions