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

Dropdown reverts to previous value

I have a dropdown with a collection of hours as its item source.

ClearCollect(dropDownHours, {Title:00,Title:01,Title:02,Title:03,Title:04 etc to 24})

I am using a single item collection to hold form data for calculation before I patch it back to a sharepoint list.

 

The dropdown has the following parameters

Items: dropDownHours

Default: First(workingItem).'Start Hour'

OnChange: Patch(workingItem,First(workingItem),{'Start Hour':Value(Dropdown1_4.Selected.Value)})

 

When I select an item in the dropdown the collection 'workingItem' is patched correctly but the dropdown then displays the previously selected option.

If I select the same option twice it shows the correct option.

 

Is this expected behaviour?

Is there a better way to work with temporary data and have it displayed accuratly when the dropdowns are changed?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Champion
Community Champion

Hi,

If you would like the Dropdown to revert back to the Default value, you will need to trigger its Reset property true then back to false. This can be done with a context variable.

 

Wherever you place your Patch() formula, have it trigger the reset:

Patch();

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

Then set the Reset property of your Dropdown to:

resetdrop

 

This means, "Patch the records, then update the resetdrop variable true, then false so that the Dropdown menu goes back to its Default value."

Microsoft Employee
@8bitclassroom

View solution in original post

4 REPLIES 4
Advocate I
Advocate I

I did the same as you with a few modifications, and it works as expected.

 

No Collection

 

Items: ["01","02","03", ... ,"24"]

Default: First(WorkingItem).StartHour

Patch(WorkingItem,First(WorkingItem),{StartHour:Value(Dropdown1_4.Selected.Value)})

 

With a space in the SharePoint list field name

First(WorkingItem).Start_x0020_Hour

Patch(WorkingItem,First(WorkingItem),{Start_x0020_Hour:Value(Dropdown1_4.Selected.Value)})

Community Champion
Community Champion

Hi,

If you would like the Dropdown to revert back to the Default value, you will need to trigger its Reset property true then back to false. This can be done with a context variable.

 

Wherever you place your Patch() formula, have it trigger the reset:

Patch();

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

Then set the Reset property of your Dropdown to:

resetdrop

 

This means, "Patch the records, then update the resetdrop variable true, then false so that the Dropdown menu goes back to its Default value."

Microsoft Employee
@8bitclassroom

View solution in original post

Thanks mr-dang and johnselnaes both ways solve the problem.

mr-dang's solution marked because it means I can keep my current data structures.

Kudos to johnselnaes, I will probably move to using simpler data structures in future.

Hi @SimonMeadows,

It seems my solution is outdated now. I have a new method that is not too much to learn and has great value as a best practice.

 

First, you can use the Reset() function to reset a control to its default:

Reset(dropDownHours)

Reset() works well for individual controls if you do not have too many. 

 

  • Problem 1: you have too many controls you want to reset and you'd need to type out every control you want to reset (side note, a form control could already reset, this would be a context outside of a form).
  • Problem 2: you want many controls to reset---but from many trigger points. For instance, you want a button on one screen to reset all the controls, but you also have a button on another screen that you want to use to reset the same controls, but you don't want to have to copy paste the formula for resetting all the controls in multiple places

 

This method consists of:

  • toggle
  • button
  • all the controls you want to reset

 

Insert one button, change its OnSelect property to:

Set(resetControls,true)

Insert a toggle, change its OnCheck property to:

Reset(Dropdown2);
Reset(ListBox1);
Reset(Radio1);
... everything you want to reset...

Set(resetControls,false)

The button triggers a variable called 'resetControls' to true. When 'resetControls' is true, the toggle activates (it becomes checked). When the toggle activates, it performs all the reset actions, then it switches itself off by setting the 'resetControls' variable to false again. 

 

In each place where you want to reset the controls, you would simply copy and paste:

Set(resetControls,true)

 

Benefits

  • trigger the same action in multiple places without much duplication
  • centralized formula -- you can edit one formula instead of editing duplicated formulas everywhere
  • apply this skill to other actions besides Reset()

 

I hope this helps anyone who is coming to this solution 🙂

 

Mr. Dang

 

__________________

Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (21,489)