{"id":3659,"date":"2019-10-01T09:54:20","date_gmt":"2019-10-01T16:54:20","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/introducing-onreset-property-of-component\/"},"modified":"2019-10-01T09:54:20","modified_gmt":"2019-10-01T16:54:20","slug":"introducing-onreset-property-of-component","status":"publish","type":"power-apps","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-apps\/introducing-onreset-property-of-component\/","title":{"rendered":"Introducing OnReset property of component"},"content":{"rendered":"
I am excited to introduce the OnReset property of components. With OnReset, you can specify\u00a0behavior formulas<\/a>\u00a0that run when an event resets a component. You can use OnReset to perform initialization, clear input, and reset values when the\u00a0Reset<\/strong>\u00a0function is run on the component instances.<\/a><\/p>\n In a component master, select the component itself. Go to the drop-down list of properties on the right side of the formula bar. Select\u00a0OnReset<\/strong>\u00a0and then enter one or more formulas.<\/p>\n <\/p>\n To trigger\u00a0OnReset <\/strong>on a component instance, configure a control to Reset<\/a> the component. Here are two examples.<\/p>\n \u00a0<\/p>\n <\/p>\n In this example, OnReset is used to reset a time picker. In this time picker component, there are two variables used to display the time\u00a0_selectedHour<\/strong> and _selectedMinute.<\/strong>\u00a0 When the picker gets reset, these variables should be reset to a default value, say 12: 12.\u00a0 The OnReset property for the component has the following formula:<\/p>\n To trigger reset, go to a screen and insert an instance of the component. Add a button and configure\u00a0OnSelect <\/strong>of the button to call Reset() on the component instance:<\/p>\n <\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n <\/p>\n Building dialogs in canvas apps can be tricky, as a dialog visibility can be changed from inside the component (e.g. an ‘OK’ button) or outside it (show\/hide the dialog). OnReset to the rescue!<\/p>\n You can use OnReset property to toggle the visibility of a component.\u00a0 The key steps are: (a) exposing a variable as an output, (b) wiring it with the Visible<\/strong> property of the component instance, and (c) using OnReset to reset the variable. The full app is available for download here<\/a>.<\/p>\n Here is how to build a simple dialog component. In the component master, configure:<\/p>\n <\/p>\n In app screen:<\/p>\n \u00a0<\/p>\n Besides resetting a component instance from the outside of the component, there is another method to trigger the OnReset from the inside. “Raise OnReset when value changes” is an option when creating a custom input property, and it allows the value changes of this property to trigger OnReset of the component. This method is designed to set and reset default value easily. Here is an example.<\/p>\n <\/p>\n \u00a0<\/p>\n <\/p>\n \u00a0<\/p>\n This is an example of reviewing order numbers and updating the numbers. (Download the example app including the component here<\/a>.) The numeric up and down component is used to increase or decrease number of orders. When\u00a0selecting the gallery on the left, the default number of numeric up and down component is reset to display the order number of selected tool. “Raise OnReset when value changes” made it possible to reset the default value when the input changes. Here is how:<\/p>\n And in the text input control:<\/p>\n Being able to reset default value and set behavior for component is important to make components flexible in various scenarios. It was also one of the top questions and asks for components. Share your feedback with us and check out examples shared in the community component gallery<\/a>. Happy building!<\/p>\n","protected":false},"excerpt":{"rendered":" Introducing the OnReset property of components. With OnReset, you can specify\u00a0behavior formulas\u00a0that run when an event resets a component. Read details and examples.<\/p>\n","protected":false},"author":147,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","power-apps-category":[1656,1664],"power-apps-tag":[1604],"coauthors":[2083],"class_list":["post-3659","power-apps","type-power-apps","status-publish","hentry","power-apps-category-new-features","power-apps-category-uncategorized","power-apps-tag-events"],"yoast_head":"\nOnReset<\/h2>\n
Reset time picker<\/h2>\n
\nYou can download the time picker component here<\/a>.<\/p>\nSet(_selectedHour,12); Set(_selectedMinute,12)<\/pre>\n
Show and dismiss a dialog<\/h2>\n
\n
OnSelect = Set(visible_variable, false)<\/pre>\n
\n
OnReset\u00a0 = Set(visible_variable, true).<\/pre>\n
\n
\n
OnSelect = Reset(Dialog_1)<\/pre>\n
\n
Visible <\/strong>= Dialog_1.Dialog_1.CustomProperty1<\/pre>\n
Custom properties trigger OnReset when value changes<\/h2>\n
\n
OnReset =\u00a0Set(_numericValue,'Numeric up down'.DefaultValue)<\/span><\/pre>\n
Default = If(IsBlank(_numericValue), 'Numeric up down'.DefaultValue, _numericValue)<\/pre>\n