0

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.

The Problem

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?

0

Ok so I didn't manage to solve this directly, but I did accomplish my intent behind this quesion.

The intent behind this was to pre-populate a field collection from another node on a node create form with an ajax call.

I'm still not sure how you alter the fields in a field collection on a form and I'll leave this question open in case anyone knows, however if you're looking to pre-populate field collections onto a node, then this blog post has an answer:

http://drupal.cocomore.com/blog/field-collections-exposed

And I posted an example using ajax to do this in an answer to this question (where I think it's more relevant): How to create (& pre-populate) multiple “field collection” fields on an ajax call

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.