nathanvda / cocoon

Dynamic nested forms using jQuery made easy; works with formtastic, simple_form or default forms
http://github.com/nathanvda/cocoon
MIT License
3.08k stars 383 forks source link

Randomly auto send form after pressing on "link_to_add_association" #626

Closed anko20094 closed 1 year ago

anko20094 commented 1 year ago

https://user-images.githubusercontent.com/31440971/191000814-86a72939-de4b-42c4-8bec-b62f06d125e2.mp4

When I click on "link_to_add_association" it sometimes send form instead to add new nested form... _form.html.slim

= link_to_add_association 'Add product', f, :products, 'data-association-insertion-method': :after
      #products
        = f.simple_fields_for :products do |product|
          = render 'product_fields', f: product
    = f.error_notification
nathanvda commented 1 year ago

Thanks for including the recording to clarify the bug.

However, without more code I fail to see why this behaviour would be caused by the link_to_add_association link.

In general I am trying to understand why the "link" would suddenly behave to post the form. The only explanation i can think of now is that your link is inside a button, if then the javascript is disabled for some reason (an error?), clicking the button would submit the form. However, from the little code you showed that does not seem to be the case.

I am guessing you have some callbacks to manipulate the inserted piece of view, could they be the cause of this?

Can you show more code?

anko20094 commented 1 year ago

https://user-images.githubusercontent.com/31440971/191706701-8b36dc34-5f80-45b8-9c69-59424b5a3939.mp4 @nathanvda Thank you very much! Indeed problem was due tag 'Button'. When I separated it, cocoon works perfect image