File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -125,11 +125,12 @@ private function initializeFormValues(): void
125
125
126
126
private function submitForm (bool $ validateAll = true ): void
127
127
{
128
+ if (null !== $ this ->formView ) {
129
+ throw new \LogicException ('The submitForm() method is being called, but the FormView has already been built. Are you calling $this->getForm() - which creates the FormView - before submitting the form? ' );
130
+ }
131
+
128
132
$ form = $ this ->getFormInstance ();
129
133
$ form ->submit ($ this ->formValues );
130
- // re-extract the "view" values in case the submitted data
131
- // changed the underlying data or structure of the form
132
- $ this ->formValues = $ this ->extractFormValues ($ this ->getForm ());
133
134
134
135
if ($ validateAll ) {
135
136
// mark the entire component as validated
@@ -143,6 +144,10 @@ private function submitForm(bool $validateAll = true): void
143
144
$ this ->clearErrorsForNonValidatedFields ($ form , $ this ->getFormName ());
144
145
}
145
146
147
+ // re-extract the "view" values in case the submitted data
148
+ // changed the underlying data or structure of the form
149
+ $ this ->formValues = $ this ->extractFormValues ($ this ->getForm ());
150
+
146
151
if (!$ form ->isValid ()) {
147
152
throw new UnprocessableEntityHttpException ('Form validation failed in component ' );
148
153
}
Original file line number Diff line number Diff line change 12
12
namespace Symfony \UX \LiveComponent \Tests \Fixture \Dto ;
13
13
14
14
use Symfony \Component \Validator \Constraints \Length ;
15
+ use Symfony \Component \Validator \Constraints \NotBlank ;
15
16
16
17
class BlogPost
17
18
{
19
+ #[NotBlank(message: 'The title field should not be blank ' )]
18
20
public $ title ;
19
21
20
- #[Length(min: 100 )]
22
+ #[Length(min: 100 , minMessage: ' The content field is too short ' )]
21
23
public $ content ;
22
24
23
25
public $ comments = [];
Original file line number Diff line number Diff line change @@ -55,15 +55,16 @@ public function testFormValuesRebuildAfterFormChanges(): void
55
55
'headers ' => ['X-CSRF-TOKEN ' => $ token ],
56
56
])
57
57
->assertStatus (422 )
58
- ->dump ()
59
58
// look for original embedded form
60
59
->assertContains ('<textarea id="blog_post_form_comments_0_content" ' )
61
60
// look for new embedded form
62
61
->assertContains ('<textarea id="blog_post_form_comments_1_content" ' )
63
62
// changed text is still present
64
63
->assertContains ('changed description by user</textarea> ' )
65
64
// check that validation happened and stuck
66
- ->assertContains ('This value is too short. It should have 100 characters or more. ' )
65
+ ->assertContains ('The content field is too short ' )
66
+ // make sure the title field did not suddenly become validated
67
+ ->assertNotContains ('The title field should not be blank ' )
67
68
->use (function (Crawler $ crawler ) {
68
69
$ div = $ crawler ->filter ('[data-controller="live"] ' );
69
70
$ liveData = json_decode ($ div ->attr ('data-live-data-value ' ), true );
You can’t perform that action at this time.
0 commit comments