cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WinIOSAndroid
Advocate I
Advocate I

Reset dropdown Selected?

I have added a dropdown to a screen populated from a collection : however, if a user makes a selection, it remembers that selection whenever they return to that screen, whereas I want it to revert to the first ('dummy') item 'Select from the list...'

 

I have set 'reset' to true and tried adding a default value, but nothing seems to work.

 

When does reset kick in?

When is a default value used?

Is there another way of doing this?

24 REPLIES 24

Try as I might, I couldn't get the dropdown to reset using the form solution. However, I have come up with a bodgy workaround.

 

I set up a global variable (ClearCollect...) on the home page which creates a collection 'vars' with a variable 'temp' = 1 : on every page, the OnVisible multiplies it by -1 so in effect every time the page is loaded, the variable swings from 1 to -1.

My dropdown list of items is also held in a collection : in each page's OnVisible,

 

ClearCollect(vars,{temp:First(vars).temp*-1});

If(First(vars).temp=1,

ClearCollect(menulist,{Title:"Go to...",Screen:home,URL:""},menu),

ClearCollect(menulist,{Title:"Go to... ",Screen:home,URL:""},menu))

 

and the dropdown's items = menulist

 

in other words, I subtly change the list of items driving the dropdown (note the space after the second 'Go to... ') every time the page loads, so it forgets the old Selected

 

inelegant but it seems to work!

KC
Kudo Kingpin
Kudo Kingpin

Thought I'd double check this in the new Templates, there is inconsistent behaviour in the demo app as well.

 The Cost Estimator example contains a stand alone dropdown control.

 

No changes, straight out of the box. 

Scenario 1:

Cost Estimator Template - This works when launching the app in the browser but does not work in editing - the dropdown in the demo resets to it's default value when the OpenJobPage is navigated to. 

 

The Reset property is blank

 

Scenario 2:

Save Cost Estimator Template to your environment -  The dropdown no longer resets to it's default value when the OpenJobPage is navigated to in either the browser or the editor. 

 

The Reset property is blank

 

 

Meneghino
Community Champion
Community Champion

Hi all.  At some point @flyte asked how to reset a stand alone (e.g.  drop down) control to the default value.

 

You do this by setting the Reset property of any control to a context variable, say ResetVar.

 

Then you put this code into whatever event you want to trigger the reset (e.g. a button OnSelect or a OnVisible or OnHidden etc.)

UpdateContext({ResetVar: true}); UpdateContext({ResetVar: false})

Then all of the controls with ResetVar as Reset property will be simultanaously reset to the Default value.

 

I am not sure about forms as I avoid them, I find it much easier in the end to use stand-alone controls and Patch() functions.

View solution in original post

So thats how you do it! 

 

I would like to formally ask M$ to create a Reset() function for each object instead of forcing you to have to change a context var back and forth, seems like a lot of extra work to do a seemingly simple task...

 

Thanks meneghino for the wrinkle in the brain!

Actually there is a Reset property for most controls (text inputs, drop downs etc.) and you can set all of them to the same ResetVar so that all controls reset synchronously (for example after a Patch operation).  It's quite ok I think,

 

The only problem is that there is no Reset property for galleries, please add your kudos to this if you agree:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/Add-a-Reset-property-to-galleries/idi-p/18128

Thanks @Meneghino for the solution - I wish it were more obvious. I'm assuming that we can "toggle" the ResetVar during Navigation? (passing two UpdateContext's in the Navigation param?

Nono, what I am talking about is actually just having a function Reset() for each control that can be called rather than a property that needs to be toggled back and forth to work. 

 

In other words, instead of:

 

1. Set reset property of all controls to resetvar

2. Write update contexts in an event property to toggle true/false

 

Be able to

1. Call Control.reset() from an event property to reset controls

 

You could even make it where grouped controls have a common .reset() function to enable multiple resets at once.

 

 

I would say your best bet there is to make the screen's OnVisible: If(resgo,UpdateContext({resetvar:true});UpdateContext({resetvar:false}),false)

 

then pass resgo to the screen when you navigate to it, if you want to reset the controls, then pass {resgo:true} when you navigate to the page.

 

I dont know if that would work (im not at my dev station) but maybe?

Meneghino
Community Champion
Community Champion

No problems, it took me a while to discover and it is obvious once you know it.

I think you cannot pass two values for the same context variable in a Navigate parameter, so you cannot toggle directly with Navigate.

There are two things you can do:

1) If you want to reset every time someone navigates to (or from) a screen just set its OnVisible or OnHidden properties to the toggle (i.e. two UpdateContexts one after the other)

2) If you want to control whether the reset is triggered then have another context variable (ResetOnVisible) and then set the navigation context reset as {ResetOnVisible: true}  (or false depending on what you need) then set the OnVisible property of the screen you are navigating to to:

If(ResetOnVisible, UpdateContext({ResetVar: true}); UpdateContext({ResetVar: false, ResetOnVisible: false})

Hi @TschoofBAH  I now see what you mean by a reset function, thanks for clarifying.

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (18,602)