Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiSelect with dynamic values for formbuilder #2699

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions docs/content/1_docs/4_form-fields/06_multi-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,38 @@ public function sectors() {
- In your repository, make sure to sync the association when saving:

```php
public function afterSave($object, $fields)
public function afterSave($object, $fields): void
{
$object->sectors()->sync($fields['sectors'] ?? []);

parent::afterSave($object, $fields);
}
```

:::tabs=currenttab.FormBuilder&items.FormBuilder|FormView:::
:::tab=name.FormBuilder:::

```php
$form->add(
MultiSelect::make()
->name('sectors')
->options(
Options::fromArray(app()->make(SectorsRepository::class)->listAll()->toArray())
)
);
```

:::#tab:::

:::tab=name.FormView:::

- In your controller, add to the formData the collection of options:

```php
protected function formData($request)
{
return [
'sectors' => app()->make(SectorRepository::class)->listAll()
'sectors' => app()->make(SectorRepository::class)->listAll()->toArray()
];
}
```
Expand All @@ -229,6 +246,9 @@ protected function formData($request)
/>
```

:::#tab:::
:::#tabs:::

When used in a [block](../5_block-editor), no migration is needed.

## Multi Select Inline
Expand Down
Loading