How to automatically populate fields in FormFlow based on previous input

98 Views Asked by At

I'm using FormFlow and would like to automatically populate some of the next fields based on the answers.

For instance in the following code, if a user answers the question of CloudType with NationalCloud I would like to automatically set the value of ClusterPurpose to 1 and not to ask for it's value. In case a user answer CloudType with PublicCloud I would like to ask for the ClusterPurpose.

What is the best way to achieve this?

public static IForm<MyForm> BuildForm()
        {
            var customFormBuilder = CreateCustomFormBuilder<MyForm>();
            return customFormBuilder
                .Field(nameof(CloudType))
                .Field(nameof(NationalCloudType), active: state => !IsPublicCloudChosen(state))
                .Field(nameof(ClusterPurpose))
                .CompleteRequestForm();
        }
    }

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

You can set state.ClusterPurpose when validating CloudType input and hide ClusterPurpose field if state.CloudType is NationalCloud.