@@ -813,7 +813,12 @@ recreate the *same* form, we pass in the ``Post`` object and set it as a
813
813
``LiveProp ``.
814
814
815
815
The template for this component will render the form, which is available
816
- as ``this.form `` thanks to the trait:
816
+ as ``form `` thanks to the trait:
817
+
818
+ .. versionadded :: 2.1
819
+
820
+ The ability to access ``form `` directly in your component's template
821
+ was added in LiveComponents 2.1. Previously ``this.form `` was required.
817
822
818
823
.. code-block :: twig
819
824
@@ -833,13 +838,13 @@ as ``this.form`` thanks to the trait:
833
838
#}
834
839
data-action="change->live#update"
835
840
>
836
- {{ form_start(this. form) }}
837
- {{ form_row(this. form.title) }}
838
- {{ form_row(this. form.slug) }}
839
- {{ form_row(this. form.content) }}
841
+ {{ form_start(form) }}
842
+ {{ form_row(form.title) }}
843
+ {{ form_row(form.slug) }}
844
+ {{ form_row(form.content) }}
840
845
841
846
<button>Save</button>
842
- {{ form_end(this. form) }}
847
+ {{ form_end(form) }}
843
848
</div>
844
849
845
850
Mostly, this is a pretty boring template! It includes the normal
@@ -1027,7 +1032,7 @@ Finally, tell the ``form`` element to use this action:
1027
1032
{# templates/components/post_form.html.twig #}
1028
1033
{# ... #}
1029
1034
1030
- {{ form_start(this. form, {
1035
+ {{ form_start(form, {
1031
1036
attr: {
1032
1037
'data-action': 'live#action',
1033
1038
'data-action-name': 'prevent|save'
@@ -1148,11 +1153,11 @@ and ``removeComment()`` actions:
1148
1153
.. code-block :: twig
1149
1154
1150
1155
<div{{ attributes }}>
1151
- {{ form_start(this. form) }}
1152
- {{ form_row(this. form.title) }}
1156
+ {{ form_start(form) }}
1157
+ {{ form_row(form.title) }}
1153
1158
1154
1159
<h3>Comments:</h3>
1155
- {% for key, commentForm in this. form.comments %}
1160
+ {% for key, commentForm in form.comments %}
1156
1161
<button
1157
1162
data-action="live#action"
1158
1163
data-action-name="removeComment(index={{ key }})"
@@ -1164,7 +1169,7 @@ and ``removeComment()`` actions:
1164
1169
</div>
1165
1170
1166
1171
{# avoid an extra label for this field #}
1167
- {% do this. form.comments.setRendered %}
1172
+ {% do form.comments.setRendered %}
1168
1173
1169
1174
<button
1170
1175
data-action="live#action"
@@ -1173,7 +1178,7 @@ and ``removeComment()`` actions:
1173
1178
>+ Add Comment</button>
1174
1179
1175
1180
<button type="submit" >Save</button>
1176
- {{ form_end(this. form) }}
1181
+ {{ form_end(form) }}
1177
1182
</div>
1178
1183
1179
1184
Done! Behind the scenes, it works like this:
0 commit comments