Make a Field Focus and Required Dynamically in PowerApps

Introduction

This article will learn how to improve user experience with SetFocus and make a field as required in Power App.

SetFocus() function in Power Apps

The SetFocus is used to move an input focus to a specific control. the user's Keystrokes are received by that control, allowing them to enter text in that input control.

When should we use the SetFocus function?

Users can use the SetFocus function for the below application.

  • When a screen is displayed, focus the first input control with onvisible property of the screen.
  • Newly exposed control or enabled input control to guide the user that what comes next to enter data faster.

Limitations for the SetFocus function

This function can be used for controls.

  • Text input control
  • Image control
  • Label Control
  • Icon Control
  • Button control

Syntax

SetFocus(Control)

The SetFocus function gives control to the input focus.

Implementing the SetFocus function in the Canvas app

In our scenario, we are adding SetFocus control and making Field as required during the “Onchange” property of input toggle control.

This will dynamically focus the required control and make the field as required as per the user input.

If(employee_info.Value=true,SetFocus(DataCardValue2))

We are writing above Power FX formula above on the “Onchange” property of toggle control. When a toggle is turned on, the employee ID field will be focused and marked as required.

Please below the screen shorts of canvas apps.

Canvas Apps

To make the field required, we are writing the below formula on the field required property.

employee_info.Value=true

Field Required

Final screen

We have turned the employee toggle on in the below screen, You can notice that the employee ID field is focused, and it's required.

Employees Information


Similar Articles