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:
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:
Saving via SaveButton.OnSelect and thus triggering ResetForm yields:
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:
Saving and triggering ResetForm again yields:
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:
Last tested with:
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.
Solved! Go to Solution.
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.
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.
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.
Found a workaround in the above link.
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.
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...
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.
I voted up too & commented.
So, I got my Combobox working with these settings:
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.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
178 | |
94 | |
61 | |
59 | |
58 |
User | Count |
---|---|
254 | |
164 | |
91 | |
79 | |
70 |