Validate fields for manual member
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
philipp lang 2024-06-19 10:30:07 +02:00
parent 40407214e3
commit 03c19aa5fb
2 changed files with 20 additions and 10 deletions

View File

@ -42,12 +42,13 @@ class NamiField extends Field
public function getRegistrationRules(Form $form): array public function getRegistrationRules(Form $form): array
{ {
$rules = [$this->key => 'present|array']; $rules = [$this->key => 'present|array'];
$inputMembers = request($this->key);
foreach ($form->getFields()->forMembers()->noNamiField() as $field) { foreach ($form->getFields()->noNamiField()->forMembers() as $field) {
$r = $field->getRegistrationRules($form); foreach ($field->getRegistrationRules($form) as $ruleKey => $rule) {
foreach ($inputMembers as $memberIndex => $inputMember) {
foreach ($r as $ruleKey => $rule) { $rules[$this->key . '.' . $memberIndex . '.' . $ruleKey] = !$inputMember['id'] || $field->namiType === null ? $rule : '';
$rules[$this->key . '.*.' . $ruleKey] = $field->namiType === null ? $rule : ''; }
} }
} }
@ -69,12 +70,9 @@ class NamiField extends Field
return []; return [];
} }
$c = $form->getFields()->noNamiField()->forMembers(); foreach ($form->getFields()->noNamiField()->forMembers() as $field) {
foreach ($c as $field) {
foreach ($field->getRegistrationRules($form) as $ruleKey => $rule) { foreach ($field->getRegistrationRules($form) as $ruleKey => $rule) {
foreach ($inputMembers as $memberIndex => $inputMember) { foreach ($inputMembers as $memberIndex => $inputMember) {
$message = $field->name . ' für ein Mitglied'; $message = $field->name . ' für ein Mitglied';
$rules = array_merge( $rules = array_merge(
$rules, $rules,

View File

@ -575,7 +575,6 @@ class FormRegisterActionTest extends FormTestCase
public function testItAddsMemberForNonNami(): void public function testItAddsMemberForNonNami(): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();
$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('gender')->namiType(NamiType::GENDER)->required(false),
@ -589,6 +588,19 @@ class FormRegisterActionTest extends FormTestCase
$this->assertEquals('Herr', $form->participants->get(1)->data['gender']); $this->assertEquals('Herr', $form->participants->get(1)->data['gender']);
} }
public function testItValidatesNamiTypeFieldsForNonMembers(): void
{
$this->login()->loginNami();
$form = Form::factory()->fields([
$this->namiField('members'),
$this->textField('gender')->name('Geschlecht')->namiType(NamiType::GENDER)->required(true),
])
->create();
$this->register($form, ['gender' => 'Herr', 'members' => [['id' => null, 'gender' => null]]])
->assertJsonValidationErrors(['members.0.gender' => 'Geschlecht für ein Mitglied ist erforderlich.']);
}
public function testItValidatesMembersFields(): void public function testItValidatesMembersFields(): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();