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

Limit number of nested fields wiki improvement #599

Closed kevkev300 closed 3 years ago

kevkev300 commented 3 years ago

From your wiki: https://github.com/nathanvda/cocoon/wiki/How-to-limit-the-number-of-nested-fields

First, I think it's pretty awesome, that you provide some wiki articles, thanks for that!

I tried your code in the said article as it was the first to pop up in Google for me. It worked in some cases, and in others not. I was able to fix it by simply adding :visible for the length:

if ($('#emissions_custom_pages .nested-fields:visible').length == 5) {

Hopefully, that helps others as well 😄

nathanvda commented 3 years ago

Thanks for the remark. I have updated the wiki-page accordingly.

Better late than never.