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) {
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 😄