OnChange of Combobox is triggered when DefaultSelectedItems is assigned some value. Unlike dropdown control. How to assign default value to combobox control without triggereing its onchange event?
Detailed Explanation
Btn_Initialize
OnSelect
ClearCollect(
GalData,
Table(
{
CmBx1:{Id:1,Value:"Item1_1"},
CmBx2:{Id:1,Value:"Item2_1"},
CmBx3:{Id:1,Value:"Item3_1"}
},
{
CmBx1:{Id:2,Value:"Item1_2"},
CmBx2:{Id:2,Value:"Item2_2"},
CmBx3:{Id:2,Value:"Item3_2"}
}
)
);
Collection Gallery & Selection Gallery
Items
GalData
ComboBox1
Items
Table(
{Id:1, Value:"Item 1_1"},
{Id:2, Value:"Item 1_2"},
{Id:3, Value:"Item 1_3"},
{Id:4, Value:"Item 1_4"},
{Id:5, Value:"Item 1_5"},
{Id:6, Value:"Item 1_6"},
{Id:7, Value:"Item 1_7"},
{Id:8, Value:"Item 1_8"},
{Id:9, Value:"Item 1_9"},
{Id:10, Value:"Item 1_10"}
)
DefaultSelectedItems
ThisItem.CmBx1
SelectMultiple
false
OnChange
Patch(
GalData, LookUp(GalData,CmBx1.Id=ThisItem.CmBx1.Id),
{
CmBx2:{Id: -1,Value: Blank()},
CmBx3:{Id: -1,Value: Blank()}
}
)
ISSUE
I'm having issue with this OnChange in ComboBox Control.
The same can be achieved using dropdown control without any issue, why Combobox is behaving abruptly?
I was answering your question on unexpected behaviour, which I have also experienced and I believe is a bug (therefore I cannot explain the reason). My "solution" is (as I noted) a workaround that you really should not have to do, but is the only one I can think of. My personal solution has been to use Drop-Downs instead of Combo Boxes if I want OnChange triggered directly from Edit mode from them (which I need rarely in my designs). You can also consider presenting the user with View mode and set the Variable on the button that puts the form in Edit mode.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
@WarrenBelz According to your solution,
Screen3
UpdateContext({varPatchNow:false})
ComboBox control
UpdateContext({varPatchNow:true})
If(
varPatchNow,
Patch(
GalData,
{CmBx1.Id:ThisItem.CmBx1.Id},
{
CmBx2:
{
Id: -1,
Value: Blank()
},
CmBx3:
{
Id: -1,
Value: Blank()
}
}
)
);
UpdateContext({varPatchNow:false});
Which is showing unexpected behaviour
Please explain why it is so...?
A Solution I found.
UpdateContext({varPatchNow:true})​
Now Combo Box works fine but overhead is that if I want to change a value then everytime I need to click on icon next to it
Looking for solution without this icon and extra click
You are doing this - my code simply stops the event triggering when the form loads (which is the question you posted The same can be achieved using dropdown control without any issue, why Combobox is behaving abruptly ). You need to set the Variable to true after it loads (probably present the Form in View mode than put the code on the Edit button) and then the OnChange event will work when the combo box changes - as I said, this is a workaround for the combo box behaviour that you would not expect.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
@WarrenBelz I wanted to patch during "OnChange" which is possible using dropdown control. Please tell me how to patch onChange of combo box control.
I wanted to patch onchange of combobox control blank value to 'Cmbx2' and 'Cmbx3'
Please tell how to do this ?
Hi @pcakhilnadh ,
Answer is still the same - set a Variable at Screen OnVisible
UpdateContext({varPatchNow:false})
Combo Box OnChange
If(
varPatchNow,
Patch(
GalData,
{CmBx1.Id:ThisItem.CmBx1.Id},
{
CmBx2:
{
Id: -1,
Value: Blank()
},
CmBx3:
{
Id: -1,
Value: Blank()
}
}
)
)
then when you want to actually Edit the Item
UpdateContext({varPatchNow:true})
Note this is a complete workaround, but it is the only way I know to stop this behaviour.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
@WarrenBelz I've found the root cause of the issue and modified the question ( I didn;t find a way to delete the question) Can you please check the question again
Hi @pcakhilnadh
Yes - that is a nasty habit it has when a Form is opened - you may have to conditionally trigger the OnChange on a Variable and set this when you want it to Edit the form.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
WarrenBelz
146,651
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional