diff --git a/app/Form/Fields/GroupField.php b/app/Form/Fields/GroupField.php
index 2c37ac3d..076e0cc0 100644
--- a/app/Form/Fields/GroupField.php
+++ b/app/Form/Fields/GroupField.php
@@ -16,6 +16,8 @@ class GroupField extends Field
public bool $required;
public ?string $parentField = null;
public ?int $parentGroup = null;
+ public bool $hasEmptyOption;
+ public string $emptyOptionValue;
public static function name(): string
{
@@ -28,6 +30,8 @@ class GroupField extends Field
['key' => 'required', 'default' => true, 'rules' => ['required' => 'present|boolean'], 'label' => 'Erforderlich'],
['key' => 'parent_field', 'default' => null, 'rules' => ['parent_field' => 'present|nullable|string'], 'label' => 'Übergeordnetes Feld'],
['key' => 'parent_group', 'default' => null, 'rules' => ['parent_group' => ['present', 'nullable', Rule::in(Group::pluck('id')->toArray())]], 'label' => 'Übergeordnete Gruppierung'],
+ ['key' => 'has_empty_option', 'default' => false, 'rules' => ['has_empty_option' => ['present', 'boolean']], 'label' => 'Leere Option erlauben'],
+ ['key' => 'empty_option_value', 'default' => '', 'rules' => ['empty_option_value' => ['present', 'string']], 'label' => 'Leere Option'],
];
}
@@ -42,6 +46,8 @@ class GroupField extends Field
'required' => $faker->boolean(),
'parent_field' => null,
'parent_group' => null,
+ 'has_empty_option' => $faker->boolean(),
+ 'empty_option_value' => '',
];
}
@@ -56,11 +62,11 @@ class GroupField extends Field
$rules[] = 'integer';
if ($this->parentGroup) {
- $rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id'));
+ $rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id')->push(-1));
}
if ($this->parentField && request()->input($this->parentField)) {
- $rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id'));
+ $rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id')->push(-1));
}
return [$this->key => $rules];
@@ -84,7 +90,7 @@ class GroupField extends Field
public function getPresenter(): Presenter
{
- return app(GroupPresenter::class);
+ return app(GroupPresenter::class)->field($this);
}
/**
diff --git a/app/Form/Presenters/GroupPresenter.php b/app/Form/Presenters/GroupPresenter.php
index 68d11a37..2b4410f8 100644
--- a/app/Form/Presenters/GroupPresenter.php
+++ b/app/Form/Presenters/GroupPresenter.php
@@ -2,17 +2,30 @@
namespace App\Form\Presenters;
+use App\Form\Fields\GroupField;
use App\Group;
-use Carbon\Carbon;
class GroupPresenter extends Presenter
{
+ private GroupField $field;
+
+ public function field(GroupField $field): self
+ {
+ $this->field = $field;
+
+ return $this;
+ }
+
/**
* @param ?int $value
*/
public function present($value): string
{
+ if ($value === -1) {
+ return $this->field->emptyOptionValue;
+ }
+
if (!$value) {
return '';
}
diff --git a/packages/adrema-form b/packages/adrema-form
index 31b03b69..42a2f6cb 160000
--- a/packages/adrema-form
+++ b/packages/adrema-form
@@ -1 +1 @@
-Subproject commit 31b03b69ed3d57888cd82d1bfedcd0cb2b9cdc3c
+Subproject commit 42a2f6cb08cdac743fe7c06c719ddf536bb58244
diff --git a/resources/js/views/formtemplate/GroupField.vue b/resources/js/views/formtemplate/GroupField.vue
index dd73a9fd..0d0f3aae 100644
--- a/resources/js/views/formtemplate/GroupField.vue
+++ b/resources/js/views/formtemplate/GroupField.vue
@@ -8,6 +8,24 @@
inline
@update:modelValue="$emit('update:modelValue', {...modelValue, required: $event})"
>
+
+