atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 105 forks source link

Lookup default value is breaking canLeave #2020

Closed mkrecek234 closed 6 months ago

mkrecek234 commented 1 year ago

I have a fairly complex View including tabs, and inside the tabs I have a form which itself consists of Accordions and many default fields. The form is configured to have $form->canLeave = false. However, since recently, the onLeave feature does not work properly. Sometimes, the browser warns always, even though nothing was changed in the form. Sometimes, the browser does not warn at all.

Unfortunately, I cannot reproduce this at all currently.

mvorisek commented 1 year ago

Michael, we need a repro. I advise to record your screen and do as many experiments (and /w different browsers, cleaned cache, ...) as you can. Once you reproduced it, go back to the recorded video and try to simplify/identify the repro steps.

mvorisek commented 1 year ago

Issue without repro steps is useless.

mkrecek234 commented 1 year ago

@mvorisek I agree, but I could not drill down the influencing factors which trigger the canLeave to fail, so hard to produce simplified code that reproduces the issue.

mvorisek commented 1 year ago

Can you reproduce it at least localy? If yes, feel free to send me a video in PM and I can try to figure it out.

mkrecek234 commented 1 year ago

Yes, canLeave started to fail at the time when I posted the issue. We can do a local screen share if you like - here is a video based on current develop branch - for data protection reasons I cannot share the headline, I am clicking on another menu item or crumb link and in between I am reloading the browser window. As you can see always it assumes something has changed in the form, so the pop-up comes up even though I did not change anything:

https://github.com/atk4/ui/assets/28671486/0de267a7-a9e1-4649-be1c-2550eef83925

mvorisek commented 1 year ago

Sometimes, the browser does not warn at all.

Very important claim, am I right that you can reproduce it repeatably using same sequence of steps (ie. no race condition issue)?

it assumes something has changed in the form, so the pop-up comes up even though I did not change anything

press F12 in browser and in the Debugger tab place a breakpoint at this line https://github.com/atk4/ui/blob/c093efc087/js/src/services/form.service.js#L53

it should be evident what control causes the form to be dirty

Please also note that currently changing the value back does not make the form non-dirty - can you confirm this is not the issue you face?

Also note that if you click "Auf Seite Bleiben", nothing is done and the page is not reloaded, I expect no dirtiness change - is that true? (or is clearDirtyForm in the JS called?)

mkrecek234 commented 1 year ago

@mvorisek Thank you for the instruction - I had now a form where with every reload (and no form change), the prevenLeave modal is opened. So I can reproduce it at least for this single view constantly. Putting the breakpoint where you described and loading the view, it immediately halts at the mentioned line 53. The t.data("isDirty", !0) is as follows - unfortunately I cannot figure out where the issue is.

mvorisek commented 1 year ago

Based on the chat discussion, the problem of this issue is solely in: https://github.com/atk4/ui/blob/67cfdbd00d/src/Form/Control/Lookup.php#L392

mkrecek234 commented 1 year ago

@mvorisek Thank you for helping to find the causing element for the issue. Fixed by PR #2092