'Required' Fields in Power Apps
Do you have fields that need to be required? Unfortunately, Power Apps does not currently provide the ability to set a control as required and set rules around it. All hope is not lost, however, look no further……
We can implement a clever workaround using star icons and the DisplayMode and Visible properties.
The first step in this process is to determine which conditions are needed for the field to be required. Is it always required or are there a set of conditions, such as values in other fields, that make it required? Write them down so you don’t miss any.
Add a star icon for each field that is required and position it to the left or right of the required field.
- Height: 10
- Width: 10
- Color: Red
In the ‘Visible’ property of the icon set your conditions. Simple conditions that return a Boolean (true/false) value can be added without using an If statement.
Example: IsBlank(SomeField) or IsBlank(SomeField) && SomeField.Selected = “Value”
Conditions that do not return a true/false value need to be wrapped in an If statement.
Example: If(
CountRows(
Filter(DataSource, SomeColumn = “SomeValue”) ) =0,
true,
false
)
Now you can use the Visible property of your star icons to control what the user can do next. By using the DisplayMode and Visible properties of your controls you can prevent them from being selected until the user has filled out the required field(s). Using the DisplayMode property allows the control to remain visible but keeps it from being used, while the Visible property hides the control completely.
DisplayMode Example: If(
StarIcon.Visible,
DisplayMode.Disabled,
DisplayMode.Edit
)
Visible Example: !StarIcon1.Visible Or
!StarIcon2.Visible Or
!StarIcon3.Visible
These basic principles can be used to control the visibility to see and interact with other controls as well, such as warning labels etc.
Comments
-
'Required' Fields in Power Apps
I have never used the SelectedText option for a dropdown or combobox. It's possible this might be the issue.
Here are two working examples.
-
'Required' Fields in Power Apps
@JR-BejeweledOne Thanks for the help. The straight text inputs are now working. The drop downs are permanently not visible which I'm guesting is something to do with the drop down box. Any ideas? Screen shots are below.
-
'Required' Fields in Power Apps
@JR-BejeweledOne, @ArchitectMadhan I might doing something stupid, but I cannot get the above to work, and the solution is exactly what I need.
I've added the stars and I'm trying to link each one to a either a drop down box or text input box.
If I put the following code in the star disappears with no input on the drop down. I've tried using the if statement and still get the same. Any help greatly received.
-
'Required' Fields in Power Apps
Thank you @JR-BejeweledOne
I still couldn't get it to work but after some more research (helped with your additional info) I found a formula to perform as expected:
Visible
OrgDropdown.SelectedText.Value="-"
-
'Required' Fields in Power Apps
@Anonymous Your formula will never work. You are using the 'and' operator. So saying the if the dropdown is blank AND it equals a specific value will not work. Try this instead
IsBlank(Org.Dropdown) Or OrgDropdown.Selected.Value = "-"
-
'Required' Fields in Power Apps
Thank you @JR-BejeweledOne
I've having trouble with the Visibility of the star icon.
I want the icon to appear based on the value selected in a dropdown.
If the dropdown is "-" then the star should be visible - I'm having trouble getting the formula to work.
Visible:
IsBlank(OrgDropdown) && OrgDropdown = “-”
Any help/advise is much appreciated
Luke
-
'Required' Fields in Power Apps
Hi @JR-BejeweledOne ,
Nice blog on the work around for Required fields in Power Apps. Until we get this feature in Power Apps as OOB we can use your approach.
*This post is locked for comments