Lately designing quite a few canvas apps for specific modules and this is one issue we faced recently while working for a customer.
So the customer had a gallery control which was bound to CDS contacts and then there were some additional controls like Checkbox, Text inputs etc for each gallery item where end-users can make their choices.
While the actual screen looked much different, this is the mockup I came up for this scenario.
They wanted a reset functionality i,e when the reset button is clicked, the controls inside the gallery should be set back to their default values. In other words in the example here the text inputs should be cleared and checkboxes should be unchecked.
Piece of cake we thought and out in the code on click of the Reset button
Well it didn’t work. And then tried something more stupid
Quite obvious, it won’t work. But why? A bit of search but this Microsoft Documentation just helped our understanding. This documentation on PowerApps Reset function is just what we we needed. If you go to the link, you would find this statement – “You cannot reset controls that are within a Gallery or Edit form control from outside those controls. You can reset controls from formulas on controls within the same gallery or form”
Quite obvious, the Reset button was outside the gallery and hence invoking Reset from there didn’t work. But is there a way out? Off-course there is one certainly and much easier than you may think.
So let’s first focus on the text input control inside the gallery item. There is a “Reset” property of the input item.
We are going to set it to a context variable however you can use App level variable as well which can be set using “Set” function.
You may get an error. that’s fine. This is because we haven’t yet declared the context variable.
Now on-select of the button you can write the below code.
Quite understandably, ResetTextInput when set to True, it would reset the text input to it’s default value. However you may ask the question – Why are we setting it to false? The reason for this is for the next operation when you click on the Reset button, it will again change the value from Context variable from false to true. Once a value change is detected by the framework, the Reset function would fire again.
If we don’t set to it to false post reset, it won’t work.
The same you can do for your checkbox. You can use the same variable or a different variable.
A simple one but can save you some time if you are not aware of it.
Hope this helps!
Our product offerings:
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)