Skip to content

Commit

Permalink
Document know issue about turbolinks and hotwire caching (#136)
Browse files Browse the repository at this point in the history
* Document know issue about turbolinks and hotwired caching and showing multiple file elements. Fixes #134

* Add example code to not use jquery so its simpler
  • Loading branch information
vipulnsward authored Mar 30, 2024
1 parent db4cba0 commit 7ec8ae8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,50 @@ The value will be available in the controller by `params[:post][:picture]`.

The helper is detecting the value of the `multiple` property based on the mount type in your model.

### Caching issues with Turbolinks/Hotwire

If you are facing issue, with multiple input elements being rendered due to turbolinks caching you can append this fix in the `app/javascript/application.js` to overcome this:

```
document.addEventListener('turbolinks:before-cache', function() {
const dialogClose = document.querySelector('.uploadcare--dialog__close');
if (dialogClose) {
dialogClose.dispatchEvent(new Event('click'));
}
const dialog = document.querySelector('.uploadcare--dialog');
if (dialog) {
dialog.remove();
}
const widgets = document.querySelectorAll('.uploadcare--widget');
widgets.forEach(widget => {
widget.remove();
});
});
```

Similarly if you are using [Hotwire](https://hotwired.dev/) then use can you use below code:

```
document.addEventListener('turbo:before-cache', function() {
const dialogClose = document.querySelector('.uploadcare--dialog__close');
if (dialogClose) {
dialogClose.dispatchEvent(new Event('click'));
}
const dialog = document.querySelector('.uploadcare--dialog');
if (dialog) {
dialog.remove();
}
const widgets = document.querySelectorAll('.uploadcare--widget');
widgets.forEach(widget => {
widget.remove();
});
});
```

### File and Group wrappers

When you mount either Uploadcare File or Group to an attribute, this attribute is getting wrapped with
Expand Down

0 comments on commit 7ec8ae8

Please sign in to comment.