Comments (4)
Which version of cocoon/rails/turbo are you using? In the current cocoon code (which is already pretty old) there is no addFieldListener
but we dynamically catch click-events on the link.
Try installing the latest version of cocoon (1.2.15).
from cocoon.
I add a addFieldListener to make it works, with the original code, not working
gem
- cocoon 1.2.15
- turbo-rails (2.0.5)
- rails Rails 7.1.3.2
js - "@hotwired/turbo-rails": "^7.3.0",
to make it better I paste the diff:
40c40,47
< $(document).on('click', '.add_fields', function(e) {
---
> document.querySelectorAll('.add_fields').forEach(function(element) {
> // Correctly remove the event listener
> element.removeEventListener('click', addFieldListener);
> // Add the event listener again
> element.addEventListener('click', addFieldListener);
> });
>
> function addFieldListener(e) {
103c110
< });
---
> };
134c141,142
< var hideRemoveFields = function() {
---
>
> $(document).on("ready page:load turbolinks:load", function() {
141c149
< };
---
> });
143,147d150
< $(function() {
< hideRemoveFields();
< $(document).on('page:load turbolinks:load turbo:load', hideRemoveFields); // Turbolinks support
< });
<
150a154
>
after the change, the duplications stops and works fine.
from cocoon.
Where are you including your javascript in the page? It seems with each navigation/load the javascript is evaluated again, with turbo this should normally not be the case.
from cocoon.
Im using administrate gem, they include in the top part of the layout:
but after verify my installed gem of administrate I see it in the bottom part
I will update to the master branch of the gem or the beta and back.
from cocoon.
Related Issues (20)
- Rails 6 compatibility HOT 2
- Rendering the edit screen for an item with a has_one association deletes the association HOT 5
- undefined method `template' for #<ActiveRecord::Associations::CollectionProxy HOT 1
- Inserted element does not respond to change event HOT 5
- Javascript not included in Rails 7 HOT 3
- event.preventDefault(); is not working. HOT 4
- Headache with "has_many through" associations HOT 5
- Font awesome icon with link_to_add_association HOT 2
- How can i add Rails 7 ?
- Issue with application.html.haml when running rails s HOT 2
- Latest version (1.2.15) not available on NPM HOT 1
- `link_to_remove` does not remove elements from DOM, and thus does not support clearing out enum array
- load more functionality for nested child HOT 6
- Randomly auto send form after pressing on "link_to_add_association" HOT 2
- Not rendering form field in the viewthat is nested 2 step deep in the form. HOT 2
- link_to_remove_association breaks when floated HOT 1
- element.dispatchEvent(new Event(event)) doesn't work HOT 1
- Allow attaching multiple files to a nested field HOT 2
- Release new gem version 1.2.16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocoon.