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'];
$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);
}

View File

@ -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