cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaWu
Impactful Individual
Impactful Individual

Problems with ComboBox.OnChange triggering too often and with weird timing.

Hello

Please be so kind as to read my full post before responding.
Thank you for your consideration.

In my PowerApp I often use the pattern of having something like

UpdateContext({
    unsaved: true
})

in my input controls, and only show things like Save or Reset buttons depending on unsaved.
In my MyForm.OnReset event I have

UpdateContext({
    unsaved: false
})

and my Save and Cancel buttons both use

ResetForm(MyForm)


However, I am having trouble using this together with ComboBoxes used with LookUp fields when using Save, or when entering the Screen.
It appears that the ComboBox.OnChange event gets triggered with a "weird timing" and more often than, say, TextInput.OnChange.
Hence, whenever I enter the screen or Save anything (Save triggers ResetForm in my case), ComboBox.OnChange gets triggered.
In contrast, for example TextInput.OnChange only gets triggered with an actual text change.

As an example to better highlight my problem, I have slightly modified one of my PowerApps that uses ComboBoxes in an EditForm.
I added a text context Variable logTxt with Screen.OnVisible

UpdateContext({
    logTxt: ""
})

and changed ComboBox.OnChange to, and note the "safeguard" resetting

UpdateContext({
    logTxt: logTxt & "
ComboBox.OnChange"});
If(!resetting,
    UpdateContext({deliveryUnsaved: true})
)

all my TextInput.OnChange to

UpdateContext({
    deliveryUnsaved: true,
    logTxt: logTxt & "
TextInput.OnChange"
});

and Form.OnReset

UpdateContext({
    deliveryUnsaved: false,
    logTxt: logTxt & "
Form.OnReset"
})

I also added a big Label with Label.Text set

"logTxt:
" & logTxt

and at the end of my Cancel/ResetForm and my Save buttons I have

UpdateContext({
    resetting: true
});
ResetForm(LieferungForm);
UpdateContext({
    resetting: false
})



Using, this, upon entry to the screen, with nonempty default record selected, I already see this:
image.png

That is, by "virtue" of ComboBox.OnChange triggering, I have already entered my PowerApp Mode of having unsaved changes without actually having done anything.

Changing the Text in one TextInput yields:
image.png

Saving via SaveButton.OnSelect and thus triggering ResetForm yields:
image.png

which causes an unexpected triggering on ComboBox.OnChange after Form.OnReset ignoring the resetting safeguard and the order of functions inside my SaveButton.OnSelect event.

Trying to afterwards change the ComboBox itself triggers another ComboBox.OnChange:
image.png

Saving and triggering ResetForm again yields:
image.png

which again causes an unexpected triggering of ComboBox.OnChange after Form.OnReset ignoring the resetting safeguard and the order of functions inside my Save buttons OnSelect event.

 

My questions:

  1. How do I get this setup to work even with that ComboBox.OnChange nonsense?
  2. Why is ComboBox.OnChange triggering so often, and completely inconsistent with the way OnChange gets triggered for TextInput controls?
  3. Why is ComboBox.OnChange triggering at all from using ResetForm? No other controls seem to do this.
  4. Shouldn't Form.OnReset trigger after all controls inside the form have already been reset, i.e. shouldn't Form.OnReset be in my logs after ComboBox.OnChange?

Last tested with:

App ID: 8200a3f3-30fd-44f9-b3b7-0c9e0f803c50
Session ID: 21a66c2e-a2f6-472c-bffc-a84600ce0745
PowerApps 3.19081.26


If you have read all of this properly, thank you!
If you have a solution for me or know documented answers, thank you and kudos!
    Sa.

1 ACCEPTED SOLUTION

Accepted Solutions
Rebetcha
MVP

Hi @SaWu ,

Apparently the Combo Box logic of OnChange is simply different than for the rest of the controls. I would post this as an idea to bring it under the attention of the Product Team. 

Regarding a work around: instead of using a variable you can do the Excel thing and compare the current value of the combo box to the ThisItem.Value of the corresponding field directly in the Visible property of for example the Save button. 

View solution in original post

9 REPLIES 9
Rebetcha
MVP

Hi @SaWu ,

Apparently the Combo Box logic of OnChange is simply different than for the rest of the controls. I would post this as an idea to bring it under the attention of the Product Team. 

Regarding a work around: instead of using a variable you can do the Excel thing and compare the current value of the combo box to the ThisItem.Value of the corresponding field directly in the Visible property of for example the Save button. 

SaWu
Impactful Individual
Impactful Individual

Hello @Rebetcha 

I have now posted this as an idea
https://powerusers.microsoft.com/t5/PowerApps-Ideas/Please-make-ComboBox-OnChange-trigger-consistent...
And kudos for the workaround idea.

Thank you,
    Sa.

I voted up your idea! 🙂
9dj89
Frequent Visitor
hjaf
Kudo Collector
Kudo Collector

I believe I have encountered similar issues with combobox OnChange outside of a form as well. 

I use OnChange on a combobox to trigger a set of actions that will at some point change the collection in Items for the combobox itself when certain conditions are met. I also do some manipulation on the collection in Items, if the manipulation is removed (filter in my case) it reduced the double-triggering, however, reloading the collection still triggers the OnChange, this makes sense as clearcollect() will obviously change the selection as its temporarily unavailable. 

I'm guessing that when part of a form, the form does manipulation or calculation on the datacard-Default, perhaps to update its Unsaved property(?), this is perhaps one reason for OnChange triggering. 
In any case, the documentation states:
OnChange – How the app responds when the user changes a selection.

Possible workaround to enforce behavior only on user actions: 

Use the OnSelect property to set a context variable to true, if true the OnChange sets the variable to false before proceeding otherwise it does nothing.

james_hathaway
Advocate III
Advocate III

And just to make matters worse - the timing of the ComboBox_OnChange event is not even consistent with ITSELF!

 

Example - If you add the following code to the OnChange event of the drop-down:

Set(variable, ComboBox1.Selected)

you do NOT always get the value that the combobox was changed TO - you SOMETIMES get the value that it was set to BEFORE it was changed, making it a completely useless event to use.

 

my advice - do not put ANYTHING into a ComboBox On_Change event - it is full of Bugs, and will give you all sorts of strange App behaviour...

krishangopi
Advocate I
Advocate I

Completely agree. Even today, I found stange behaviour of OnChange in combobox control in a gallary. It is set to collect the record changed using ThisItem and my surprise, one change records some six-seven records randomly and some records repeating.

 

Couldn't believe it was a bug and kept digging at the code.

 

Regards,

Krishan

I voted up, as well, and also commented this should not be an "idea" but a "bug". Why is PowerApps triggering the onChange event when the value should ONLY change once a user interacts with the control? It makes PowerApps seem very immature when this is how onChange events in dropdown lists on websites have worked for over 20 years.

KarlInOz1
Frequent Visitor

I voted up too & commented.

So, I got my Combobox working with these settings:

2022-03-31 13_33_13-Window.png

 

It works well. But I wish I could say the same for a Toggle control. That is a different beast and I just can't seem to get that one working. I have tried using the OnCheck and OnUncheck fields but I just can't tame the beast. I think I'm beaten on that one.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,092)