Quantcast
Channel: blog.atwork.at
Viewing all articles
Browse latest Browse all 1118

Tips for PowerApps-11 Make sure a value is selected in your dropdown

0
0

Working with Power Apps, have you seen that in the bound dropdown control the user can remove the selected item (even with single selection)? Well, there could be other solutions, but I want to make sure that a default value is always selected, even when the user clicks the button to remove the selection.

In this sample Power App, I have a dropdown named ProjectType that is filled from a SharePoint list and a column with choices. When the user selects an item, they can remove the selection using the x-icon on the right.

image

We want to prevent deletion and fill it with a default value instead.

The Data source of the dropdown control is set to Choices([@ProvisionTeam].ProjectType). The default value for the dropdown is a variable named myprojecttype. Through the default value, the dropdown shows the value of myprojecttype. A quick way to always select an item, even if it's removed, is to change the OnChange property for that control to the following code:

// Disallow no selection:
If(IsBlank(ProjectType.Selected.Value),
    Set(myprojecttype,{Value: "Project"});
    ,     Set(myprojecttype,{Value: ProjectType.Selected.Value});
);
Reset(ProjectType);

If a change happens, and there is no value selected, we set the variable to "Project" which is an item in the choices list. Otherwise, the variable is set to the selected item.

image

The behavior after clearing the selection is that the control displays the default value.

image

So the selected (default) value of myprojecttype always has a value that I can use for further processing.

This is a simple workaround, but useful for many scenarios.


Viewing all articles
Browse latest Browse all 1118

Latest Images

Trending Articles