Compare commits

..

2 Commits

Author SHA1 Message Date
philipp lang 49afcafbb2 Update adrema-form
continuous-integration/drone/push Build is failing Details
2024-06-18 23:55:30 +02:00
philipp lang 8f6b8e466a Fix: allow parent group field to have empty value 2024-06-18 23:54:55 +02:00
3 changed files with 18 additions and 2 deletions

View File

@ -65,7 +65,7 @@ class GroupField extends Field
$rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id')->push(-1)); $rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id')->push(-1));
} }
if ($this->parentField && request()->input($this->parentField)) { if ($this->parentField && request()->input($this->parentField) && request()->input($this->parentField) !== -1) {
$rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id')->push(-1)); $rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id')->push(-1));
} }

@ -1 +1 @@
Subproject commit 41adb7ecb0f95353c80745f050781b50a68b3a31 Subproject commit bd4118040fd2643b71f7f152ca2668f2097820a2

View File

@ -344,6 +344,22 @@ class FormRegisterActionTest extends FormTestCase
->assertJsonValidationErrors(['group' => 'Der gewählte Wert für Gruppe ist ungültig.']); ->assertJsonValidationErrors(['group' => 'Der gewählte Wert für Gruppe ist ungültig.']);
} }
public function testGroupFieldCanBeUnsetWhenGiven(): void
{
$this->login()->loginNami();
$group = Group::factory()->has(Group::factory(), 'children')->create();
$form = Form::factory()->fields([
$this->groupField('region')->emptyOptionValue('kein Bezirk')->parentGroup($group->id)->required(false),
$this->groupField('stamm')->name('Gruppe')->emptyOptionValue('kein Stamm')->parentField('region')->required(true)
])
->create();
$this->register($form, ['region' => -1, 'stamm' => -1])->assertOk();
$participants = $form->fresh()->participants;
$this->assertEquals(-1, $participants->first()->data['region']);
$this->assertEquals(-1, $participants->first()->data['stamm']);
}
public function testGroupFieldCanBeNullWhenNotRequired(): void public function testGroupFieldCanBeNullWhenNotRequired(): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();