diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index 866a1d1b024..a02853ea97e 100644 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -262,7 +262,7 @@ great, your user can't actually add any new tags yet. .. _cookbook-form-collections-new-prototype: 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. @@ -417,6 +417,11 @@ into new ``Tag`` objects and added to the ``tags`` property of the ``Task`` obje You can find a working example in this `JSFiddle`_. +.. seealso:: + + If you want to customize the HTML code in the prototype, read + :ref:`cookbook-form-custom-prototype`. + To make handling these new tags easier, add an "adder" and a "remover" method for the tags in the ``Task`` class:: diff --git a/cookbook/form/form_customization.rst b/cookbook/form/form_customization.rst index 21a34f1b346..c6265a7528a 100644 --- a/cookbook/form/form_customization.rst +++ b/cookbook/form/form_customization.rst @@ -734,6 +734,49 @@ You can also override the markup for an entire field row using the same method: widget($form) ?> +.. _cookbook-form-custom-prototype: + +How to Customize a Collection Prototype +--------------------------------------- + +When using a :doc:`collection of forms `, +the prototype can be overridden with a completely custom prototype by +overriding a block. For example, if your form field is named ``tasks``, you +will be able to change the widget for each task as follows: + +.. configuration-block:: + + .. code-block:: html+jinja + + {% form_theme form _self %} + + {% block _tasks_entry_widget %} +