From 569057eed73106908363a8462ce0dafd8b8d5c43 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 14 Aug 2018 14:57:09 +0200 Subject: [PATCH 01/18] Some wording improvements, clarifications, etc. --- form/form_collections.rst | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/form/form_collections.rst b/form/form_collections.rst index fa650cbfa82..aaf1ec023b9 100644 --- a/form/form_collections.rst +++ b/form/form_collections.rst @@ -246,40 +246,49 @@ Allowing "new" Tags with the "Prototype" Allowing the user to dynamically add new tags means that you'll need to use some JavaScript. Previously you added two tags to your form in the controller. Now let the user add as many tag forms as they need directly in the browser. -This will be done through a bit of JavaScript. The first thing you need to do is to let the form collection know that it will receive an unknown number of tags. So far you've added two tags and the form -type expects to receive exactly two, otherwise an error will be thrown: -``This form should not contain extra fields``. To make this flexible, +type expects to receive exactly two, if it gets more, the following error will be +thrown: ``This form should not contain extra fields``. To make the number flexible, add the ``allow_add`` option to your collection field:: // src/AppBundle/Form/Type/TaskType.php // ... - use Symfony\Component\Form\FormBuilderInterface; public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('description'); + // ... $builder->add('tags', CollectionType::class, array( - 'entry_type' => TagType::class, - 'entry_options' => array('label' => false), + // ... 'allow_add' => true, )); } In addition to telling the field to accept any number of submitted objects, the -``allow_add`` also makes a *"prototype"* variable available to you. This "prototype" -is a little "template" that contains all the HTML to be able to render any -new "tag" forms. To render it, make the following change to your template: +``allow_add`` option also makes a ``prototype`` variable available to you. This +"prototype" is a little "template" that contains all the HTML needed to dynamically +render any new "tag" forms with JavaScript. To render the prototype, make the following +change to the existing ``