You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was once mentioned in #3184, but I'd consider it a bug (and one that is not hard to fix, see below).
When ElFinder is used within a <form> component, clicking on any button (such as in the resize dialog) or pressing enter in an input field (such as the search bar) submits the form, causing the current page to unload. This makes ElFinder unusable. Some frameworks / UI libraries require the use form <form> and as such, make it hard to integrate / use ElFinder.
Open the dev console and run $("#elfinder").wrap("<form>")
Click in the searchbar, then press enter
The page reloads
Expected behavior
The page does not reload, the is is not asked for confirmation whether they wish to leave the page.
Suggested solution
On a technical level, the solution to both issues is simple:
For inputs, simply call event.preventDefault.
Another standard way to prevent submission on enter is to e.g. add a <button type="submit" class="Hidden" onclick="return false;" /> at the start of a <form>. This can already be done by users, so I would not consider this part too important.
This part I consider more important, since it is quite hard to work around. ElFinder uses event.stopPropagation, which makes it hard to register custom event listeners that call event.preventDefault. It's possible to use the capturing phase instead, but it's still a hack.
Describe the bug
This was once mentioned in #3184, but I'd consider it a bug (and one that is not hard to fix, see below).
When ElFinder is used within a
<form>
component, clicking on any button (such as in the resize dialog) or pressing enter in an input field (such as the search bar) submits the form, causing the current page to unload. This makes ElFinder unusable. Some frameworks / UI libraries require the use form<form>
and as such, make it hard to integrate / use ElFinder.To Reproduce
For buttons:
$("#elfinder").wrap("<form>")
Writable volume group
->Img + Txt Only
->New folder
code.png
, click onResize & Scale
Crop
tab and click on the aspect ratio lock button (with the lock icon, next to the width / height)For input fields:
$("#elfinder").wrap("<form>")
Expected behavior
The page does not reload, the is is not asked for confirmation whether they wish to leave the page.
Suggested solution
On a technical level, the solution to both issues is simple:
event.preventDefault
.<button type="submit" class="Hidden" onclick="return false;" />
at the start of a<form>
. This can already be done by users, so I would not consider this part too important.type="button"
to the<button>
elements, this will prevent the submission. By default, the type attribute defaults to submit, which I would argue is not correct.event.stopPropagation
, which makes it hard to register custom event listeners that callevent.preventDefault
. It's possible to use the capturing phase instead, but it's still a hack.Screenshots
Screencast.from.2024-10-09.20-43-09.webm
Screencast.from.2024-10-09.20-44-16.webm
The text was updated successfully, but these errors were encountered: