Fixed: Fill fields of manual member if nami type
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-06-18 21:21:02 +02:00
parent c9885a8c9c
commit 9252686e78
2 changed files with 8 additions and 8 deletions

View File

@ -43,13 +43,11 @@ class NamiField extends Field
{ {
$rules = [$this->key => 'present|array']; $rules = [$this->key => 'present|array'];
$c = $form->getFields()->forMembers()->noNamiType()->noNamiField() foreach ($form->getFields()->forMembers()->noNamiField() as $field) {
->map(fn ($field) => $field->getRegistrationRules($form)) $r = $field->getRegistrationRules($form);
->toArray();
foreach ($c as $field) { foreach ($r as $ruleKey => $rule) {
foreach ($field as $ruleKey => $rule) { $rules[$this->key . '.*.' . $ruleKey] = $field->namiType === null ? $rule : '';
$rules[$this->key . '.*.' . $ruleKey] = $rule;
} }
} }
@ -114,7 +112,7 @@ class NamiField extends Field
$member = Member::firstWhere(['mitgliedsnr' => $memberData['id']]); $member = Member::firstWhere(['mitgliedsnr' => $memberData['id']]);
$data = []; $data = [];
foreach (FieldCollection::fromRequest($form, $memberData) as $field) { foreach (FieldCollection::fromRequest($form, $memberData) as $field) {
$data[$field->key] = $field->namiType === null $data[$field->key] = $field->namiType === null || $member === null
? $field->value ? $field->value
: $field->namiType->getMemberAttribute($member, $form); : $field->namiType->getMemberAttribute($member, $form);
} }

View File

@ -562,13 +562,15 @@ class FormRegisterActionTest extends FormTestCase
$this->createMember(['mitgliedsnr' => '5505']); $this->createMember(['mitgliedsnr' => '5505']);
$form = Form::factory()->fields([ $form = Form::factory()->fields([
$this->namiField('members'), $this->namiField('members'),
$this->textField('gender')->namiType(NamiType::GENDER)->required(false),
$this->textField('other')->required(false), $this->textField('other')->required(false),
]) ])
->create(); ->create();
$this->register($form, ['other' => '::string::', 'members' => [['id' => null, 'other' => 'othervalue']]]) $this->register($form, ['other' => '::string::', 'members' => [['id' => null, 'gender' => 'Herr', 'other' => 'othervalue']]])
->assertOk(); ->assertOk();
$this->assertEquals('othervalue', $form->participants->get(1)->data['other']); $this->assertEquals('othervalue', $form->participants->get(1)->data['other']);
$this->assertEquals('Herr', $form->participants->get(1)->data['gender']);
} }
public function testItValidatesMembersFields(): void public function testItValidatesMembersFields(): void