|
3 | 3 | use Code16\Sharp\Enums\PageAlertLevel; |
4 | 4 | use Code16\Sharp\Exceptions\Form\SharpApplicativeException; |
5 | 5 | use Code16\Sharp\Exceptions\Form\SharpFormUpdateException; |
| 6 | +use Code16\Sharp\Form\Fields\SharpFormAutocompleteListField; |
| 7 | +use Code16\Sharp\Form\Fields\SharpFormAutocompleteLocalField; |
6 | 8 | use Code16\Sharp\Form\Fields\SharpFormCheckField; |
7 | 9 | use Code16\Sharp\Form\Fields\SharpFormEditorField; |
8 | 10 | use Code16\Sharp\Form\Fields\SharpFormTextField; |
@@ -307,6 +309,40 @@ public function update($id, array $data) |
307 | 309 | ->assertSessionHasErrors('name'); |
308 | 310 | }); |
309 | 311 |
|
| 312 | +it('calls prepareForValidation() before validation on applicable fields', function () { |
| 313 | + fakeFormFor('person', new class() extends PersonForm |
| 314 | + { |
| 315 | + public function buildFormFields(FieldsContainer $formFields): void |
| 316 | + { |
| 317 | + $formFields->addField( |
| 318 | + SharpFormAutocompleteListField::make('jobs') |
| 319 | + ->setItemField( |
| 320 | + SharpFormAutocompleteLocalField::make('job') |
| 321 | + ->setLocalValues([ |
| 322 | + 1 => 'Physicist', |
| 323 | + 2 => 'Chemist', |
| 324 | + ]) |
| 325 | + ) |
| 326 | + ); |
| 327 | + } |
| 328 | + |
| 329 | + public function update($id, array $data) |
| 330 | + { |
| 331 | + $this->validate($data, ['jobs.*.job' => 'required']); |
| 332 | + } |
| 333 | + }); |
| 334 | + |
| 335 | + $this |
| 336 | + ->post('/sharp/s-list/person/s-form/person', [ |
| 337 | + 'jobs' => [ |
| 338 | + ['id' => null, 'job' => ['id' => 1, 'label' => 'Physicist']], |
| 339 | + ['id' => null], |
| 340 | + ], |
| 341 | + ]) |
| 342 | + ->assertSessionDoesntHaveErrors('jobs.0.job') |
| 343 | + ->assertSessionHasErrors('jobs.1.job'); |
| 344 | +}); |
| 345 | + |
310 | 346 | it('handles application exception as 417', function () { |
311 | 347 | fakeFormFor('person', new class() extends PersonForm |
312 | 348 | { |
|
0 commit comments