Adding new objects to a form field collection

homer-dohI couldn’t think of a good title for this post. So, erm, sorry about that.

Still, if you are reading on, this may save you a headache in the future.

I came across an issue today where I was basically doing this (adding a new option at run time to a form), and it worked.

Kind of.

It would always add in the first option.

And it would add in the second option too, should I add one.

But any above the second were always lost. I couldn’t figure out why the submitted array only ever contained, at most, two items.

Out of sheer luck, I also had another collection sub form inside the very same form, which I had basically copy/pasted from.

Now, this made the whole – why the *expletive deleted* isn’t this thing working?

Turns out, I had set my prototype_name in my Form Type to something different to that in the .text().replace(regex) in my javascript.

Doh.

Still – at least I know for the future. And hopefully, if you ever make a similar mistake, you will now know how to rectify it quickly.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.