I have a data structure where a Topic has many Questions (one for many) and a Question has many answers (one for many).
I installed Questions as a built-in collection in the form of a theme, and it all works for me 100% thanks to the recording
You can see the really long line below, which I think is the prototype prototype (!) For the response form. I do not see the possibility of replacing only those related to the question [__name__] , and not related to the answer.
[__name__]
Doing normal
var newForm = prototype.replace(/__name__/g, collectionHolder.children().length);
when creating a real instance of the question form, of course, it replaces all instances of __name__ with the same value, therefore, when the data prototype is created for the response form, it has already replaced all substitutes.
__name__
This is what the prototype data for the answer form looks like when I clicked to add a real question form
<div class="control-group"> <label class="control-label">1label__</label> <div class="controls"> <div id="topic_questions_1_answers_1"> <div class="control-group"> <label for="topic_questions_1_answers_1_answerText" class="control-label">option</label> <div class="form-row-errors"></div> <div class="controls"> <input type="text" id="topic_questions_1_answers_1_answerText" name="topic[questions][1][answers][1][answerText]" required="required" maxlength="255" /> </div> </div> </div> </div>
As you can see, the __name__ placeholder does not work at all - it has already been replaced by the question form counter when the question form was created.
Is it possible to implement such a collection with many depths using the Symfony mechanism?
While he is trying to use the same placeholder for each level, I donβt see how to do it.
Do you use at least Symfony 2.1? If so, you can change the __name__ label using the prototype_name property:
prototype_name
http://symfony.com/doc/master/reference/forms/types/collection.html#prototype-name
In your form:
->add('answers', 'collection', array( 'type' => new AnswerType(), 'allow_add' => true, 'prototype_name' => 'another_name' ))