From 9252686e78407880cb9217a5cb577ddf40ab789a Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 18 Jun 2024 21:21:02 +0200 Subject: [PATCH] Fixed: Fill fields of manual member if nami type --- app/Form/Fields/NamiField.php | 12 +++++------- tests/Feature/Form/FormRegisterActionTest.php | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/Form/Fields/NamiField.php b/app/Form/Fields/NamiField.php index 21f7c1cd..38b875c8 100644 --- a/app/Form/Fields/NamiField.php +++ b/app/Form/Fields/NamiField.php @@ -43,13 +43,11 @@ class NamiField extends Field { $rules = [$this->key => 'present|array']; - $c = $form->getFields()->forMembers()->noNamiType()->noNamiField() - ->map(fn ($field) => $field->getRegistrationRules($form)) - ->toArray(); + foreach ($form->getFields()->forMembers()->noNamiField() as $field) { + $r = $field->getRegistrationRules($form); - foreach ($c as $field) { - foreach ($field as $ruleKey => $rule) { - $rules[$this->key . '.*.' . $ruleKey] = $rule; + foreach ($r as $ruleKey => $rule) { + $rules[$this->key . '.*.' . $ruleKey] = $field->namiType === null ? $rule : ''; } } @@ -114,7 +112,7 @@ class NamiField extends Field $member = Member::firstWhere(['mitgliedsnr' => $memberData['id']]); $data = []; foreach (FieldCollection::fromRequest($form, $memberData) as $field) { - $data[$field->key] = $field->namiType === null + $data[$field->key] = $field->namiType === null || $member === null ? $field->value : $field->namiType->getMemberAttribute($member, $form); } diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index d581d98d..a2e5bdc6 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -562,13 +562,15 @@ class FormRegisterActionTest extends FormTestCase $this->createMember(['mitgliedsnr' => '5505']); $form = Form::factory()->fields([ $this->namiField('members'), + $this->textField('gender')->namiType(NamiType::GENDER)->required(false), $this->textField('other')->required(false), ]) ->create(); - $this->register($form, ['other' => '::string::', 'members' => [['id' => null, 'other' => 'othervalue']]]) + $this->register($form, ['other' => '::string::', 'members' => [['id' => null, 'gender' => 'Herr', 'other' => 'othervalue']]]) ->assertOk(); $this->assertEquals('othervalue', $form->participants->get(1)->data['other']); + $this->assertEquals('Herr', $form->participants->get(1)->data['gender']); } public function testItValidatesMembersFields(): void