microsoft / powercat-creator-kit

This toolkit helps create well-designed Power App experiences on the web & mobile. It contains a component library; PCF controls and other utilities that increase developer productivity.
MIT License
321 stars 53 forks source link

[BUG]: Calendar OnChange is triggered automatically at the first visibility! #310

Closed nelson-yan closed 1 year ago

nelson-yan commented 1 year ago

Describe the bug

Calendar OnChange is triggered automatically at the first visibility!

To Reproduce Steps to reproduce the behavior:

Add a textinput box and Calendar componet in screen, set propertie as below. When I first click on textbox it briefly displays the calendar then immediately hides, the notification pop up as well. It is obviously OnChange event is fired automatically at the first visibility!

txtSelectedDate.OnSelect: UpdateContext({varShowCal:!varShowCal}) Calendar.OnChange: Notify("Calendar OnChange Fired!");UpdateContext({varShowCal:false}) datePicker.OnVisible: varShowCal

Expected behavior Calendar.OnChange won't be triggered automatically at the first visibility!

Screenshots

Additional context Community Post: https://powerusers.microsoft.com/t5/Building-Power-Apps/Creator-Kit-Date-Picker-Hide-OnChange/td-p/1910923

denise-msft commented 1 year ago

A similar issue was raised and a workaround was provided - can you please try using the suggested resolution by adding a context variable to control the behavior past an init state? See #213

As a workaround, you can try adding an additional context variable that covers this first load situation: Screen.OnVisible: UpdateContext({ init: true })

Calendar1.OnChange:

If( init,
    UpdateContext({ init: false }),
    UpdateContext({ varShowCal: false }); /* Else action expression can be whatever you wanted onChange to do */
)
nelson-yan commented 1 year ago

Yes, I did something similiar as mitigation.