This question is in the same area as a previous I asked (How to create (& pre-populate) multiple “field collection” fields on an ajax call), but with the extra level of complexity that I'm trying to alter a multiple value field inside the field collection.
I want to add a number of field instances to a multiple value field, inside a field collection when creating a node using an ajax call.
In order to create and pre-populate a multiple value field collection, you need to change the following value in the AJAX callback and then rebuild the form.
$form_state['field']['--machine-name-of-field-collection--'][LANGUAGE_NONE]['items_count'] = x;
However inside a field collection in
$form_state, there is no field information, only entity information. So while I can change
item_count for the field collection I can't alter it for any of the fields inside it.
The entity also doesn't seem to be fully created because it's on a brand new node so I can't load it and edit it.
Has anyone encountered this before? How do you work with fields inside entities on forms?