JR-BejeweledOne

'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

           reqfields.jpg

 

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

 

      reqfields1.jpgreqfields2.jpg

 

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

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.

 

Anonymous

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 = “-”

 

LAH1_0-1646370060760.png

 

Any help/advise is much appreciated

 

Luke

 

@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 = "-" 

 

Anonymous

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="-"

@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. 

 

C4178756_0-1677582018703.png

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.

C4178756_1-1677582159822.png

 

 

@C4178756 When I use this with dropdowns or ComboBoxes one of two things work.   Try setting this to either

 

IsBlank(Shift) or IsBlank(Shift.Selected.Value).  You would replace value with whatever column is being displayed.

@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. 

 

C4178756_0-1677583857202.pngC4178756_1-1677583872476.png

C4178756_2-1677583899382.png

 

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.

 

RequiredStars.png

 

@C4178756 , SelectedText does not have a value property. You need to use just Selected.Value instead, so IsBlank(Shift.Selected.Value).