Using Reset Property in Power Apps: A Better Way to Reset Nested Controls

I have looked into how to reset all the controls in the gallery at once, so I made a note of how to do that.

Reset Function

Use the Reset function to reset (return to default state) controls placed on the screen.

For example, if there is a text box on the screen,
and the user wants to reset the text, the Reset function can be used from the application to reset the text to default.

Controls in the gallery cannot be reset from outside the gallery

However, if the Reset function is called from outside the gallery for a control in the gallery, as shown in the image,

Power Apps will display a “cannot reset” error.
So, if you place a button in the gallery and call the Reset function from that button,
only the controls of the gallery item that pressed the button will be reset.

This is useful, but this method does not reset all the controls in the gallery.

Reset all controls in the gallery from outside the gallery

To reset all controls in the gallery at once, use the Reset property of the target control.
This Reset property says that the control will be reset when the value becomes “true”.
As an example, add a reset button and describe a process to update a variable of type bool with “true→false” in the OnSelect property of the button.
By setting that variable to the control’s Reset property,
the controls in the gallery are reset all at once at the timing of the button press.

Reset controls in custom component

Then when you want to reset the controls in the custom component from the app.

As shown in the image, describe the process to be called by the Reset function for each control in the OnReset function of the custom component.
Then, when the target custom component is specified with the Reset function from the app,
the controls in the custom component are reset.

Reset controls in a gallery placed inside a custom component

The last case is to reset the controls in a gallery placed in a custom component.

Method 1: Use variables in custom components

The first is to use variables in custom components.

In the OnReset function of the custom component, declare a variable of type bool, describe the process of updating it,
and set this variable to the Reset property of the control to be reset.
Then, when the app calls the Reset function for the target component,
it will be reset all at once.

This method works fine, but if it becomes necessary to “turn on” the access app scope for this component, this variable would become a “global variable” and thus affect all the same custom components placed in the app.

Therefore, if there is a possibility of turning on “access app scope”, the following method is recommended.

Method 2: Implement input properties in custom components

The second method is to implement a bool type input property in a custom component,
and put that input property into the Reset property of the control you want to reset.
Then, by declaring a variable on the application side, writing a process to update the variable,
and binding the variable to the input property,
the controls can be reset all at once.

With this method, turning on access app scope does not affect the same custom component placed elsewhere, unless the app uses variables in the wrong way.

However, this method increases the number of variables handled on the app side, so using the first method is an option if turning on access app scope is not a certainty.

Related Articles

Official

コメント

Copied title and URL