bug: when pressing create button multiple times creates duplicate records

if you press the create button multiple times by accident it creates duplicate records
29 Replies
developer
developer12mo ago
is there a way to disable the button after being pressed to prevent this behavior?
awcodes
awcodes12mo ago
It should disabled by default when the form is submitted. Can you share some code. Are you doing anything custom with the creation process?
developer
developer12mo ago
nothing especial but it takes a few seconds before redirect, so it allows an accidental double-click
awcodes
awcodes12mo ago
So the redirect is happening after the Lw request comes back from the server. It should be disabled until the request comes back.
developer
developer12mo ago
wait, i'll show you a video
developer
developer12mo ago
developer
developer12mo ago
@awcodes As you can see, after clicking on the "create" button, it temporarily deactivates before the redirection (then reactivates) which takes a few seconds, and during that time, it's possible to click multiple times
developer
developer12mo ago
awcodes
awcodes12mo ago
Why is it taking so long to redirect? That’s odd. The button uses wire:loading to disable it during requests. So something is taking a long time to redirect after the request comes back from the server.
developer
developer12mo ago
I don't know, maybe my pc is kinda slow
awcodes
awcodes12mo ago
Possibly, but I would expect the browser to be that slow.
developer
developer12mo ago
I'm using Laragon on windows 10, mariadb + nginx
awcodes
awcodes12mo ago
The request is coming back pretty quick. Can you try it in an incognito browser. I’m wondering if a browser extension could be interfering. It’s definitely something in the browser and not a filament issue though. As best as I can tell based on your vid. I guess the server could be hanging on the redirect but that seems odd to me considering the Lw request is happing so quickly.
developer
developer12mo ago
yeah, maybe... but is there a way to hide the button permanently after clicking?
awcodes
awcodes12mo ago
Not really. It’s based on the Lw request. Which it seems to be handling correctly.
developer
developer12mo ago
the truth is, I can't control which browser or system users will use I gotta find a solution
awcodes
awcodes12mo ago
Can you share the code for the resource? Just to make sure.
developer
developer12mo ago
gimme a second
awcodes
awcodes12mo ago
Also keep in mind that if your browser is doing something weird it doesn’t mean that their browser will do the same thing.
developer
developer12mo ago
awcodes
awcodes12mo ago
You can test this by asking a friend or co worker to try using your app on their system. And the rest of the resource?
developer
developer12mo ago
btw I already try the official demo https://demo.filamentphp.com/ and it works fine for me so, issue is not browser related
awcodes
awcodes12mo ago
Crazy thought. Try options(fn () => Country::….) on your select. That’s the only thing I’m seeing that you provided that could be causing a delay.
awcodes
awcodes12mo ago
Yea that’s the only standing out to me other than a possible browser issue.
developer
developer12mo ago
I changed the table pagination to a smaller number of records, and now it's a bit faster.... from 50 to 5 maybe that's why the redirection takes so long regardless, there should be a way to entirely disable the creation button
awcodes
awcodes12mo ago
I hear you but that’s not necessarily the case. The disabled is working as expected. Do you have Debugbar installed?
developer
developer12mo ago
i don't have it hey I'm gonna take a break now
awcodes
awcodes12mo ago
Ok. Install it, publish the config and disable the views to see if there’s a bottleneck at the sql query. Also did you try my suggestion about the options callback. Other than than I’m out of ideas. Especially if you’re not seeing the issue in the demo.