Argument #2 ($label) must be of type string, array given

Hi While using the form builder I have 2 json repeater on the same form. One repeater can add and delete entries I fill the form with data, everything looks ok, but if I try delete or add I get this error:
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, array given, called in /Users/xxx/cccc/vvvv/bbb/storage/framework/views/9dfcfeb9f4eab0a93b080ad35ccd3d71.php on line 83
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, array given, called in /Users/xxx/cccc/vvvv/bbb/storage/framework/views/9dfcfeb9f4eab0a93b080ad35ccd3d71.php on line 83
is it not allowed to have 2 repeater on the same form ?
20 Replies
ZedoX
ZedoX2y ago
It is certainly possible to have multiple repeaters on the same form (even nested repeaters). Could you share the relevant code snippet?
Dan Harrin
Dan Harrin2y ago
my guess is that you have a Select with the same name as a Repeater?
rabol
rabolOP2y ago
hmmm
Forms\Components\Repeater::make('placeholder_groups')
->schema([
TextInput::make('prompt_pg')->label('Prompt')
->lazy()
->required(),
Forms\Components\Select::make('who_pg')->label('who')
->options(
['Sender' => 'Sender', 'Receiver' => 'Receiver', 'Recipient' => 'Recipient', 'Ignore' => 'Ignore']
),

])
->columns(2)
->itemLabel(fn (array $state): ?string => $state['name'] ?? null),

Forms\Components\Repeater::make('placeholders')
->schema([
TextInput::make('prompt')
->lazy()
->required(),
Forms\Components\Select::make('who')
->options(
['Sender' => 'Sender', 'Receiver' => 'Receiver', 'Recipient' => 'Recipient', 'Ignore' => 'Ignore']
),
Forms\Components\Select::make('type')
->options(
['Checkbox' => 'Checkbox', 'Number' => 'Number', 'Date' => 'Date', 'Text' => 'Text', 'Signature' => 'Signature', 'Decimal' => 'Decimal', 'YesNo' => 'YesNo', 'Long Text' => 'Long Text']
),

Forms\Components\Select::make('group')
->options($this->placeholderGroups),

Forms\Components\Toggle::make('required'),
])
->columns(5)
->disableItemCreation()
->itemLabel(fn (array $state): ?string => $state['name'] ?? null),
Forms\Components\Repeater::make('placeholder_groups')
->schema([
TextInput::make('prompt_pg')->label('Prompt')
->lazy()
->required(),
Forms\Components\Select::make('who_pg')->label('who')
->options(
['Sender' => 'Sender', 'Receiver' => 'Receiver', 'Recipient' => 'Recipient', 'Ignore' => 'Ignore']
),

])
->columns(2)
->itemLabel(fn (array $state): ?string => $state['name'] ?? null),

Forms\Components\Repeater::make('placeholders')
->schema([
TextInput::make('prompt')
->lazy()
->required(),
Forms\Components\Select::make('who')
->options(
['Sender' => 'Sender', 'Receiver' => 'Receiver', 'Recipient' => 'Recipient', 'Ignore' => 'Ignore']
),
Forms\Components\Select::make('type')
->options(
['Checkbox' => 'Checkbox', 'Number' => 'Number', 'Date' => 'Date', 'Text' => 'Text', 'Signature' => 'Signature', 'Decimal' => 'Decimal', 'YesNo' => 'YesNo', 'Long Text' => 'Long Text']
),

Forms\Components\Select::make('group')
->options($this->placeholderGroups),

Forms\Components\Toggle::make('required'),
])
->columns(5)
->disableItemCreation()
->itemLabel(fn (array $state): ?string => $state['name'] ?? null),
Dan Harrin
Dan Harrin2y ago
the problem is because you are putting the repeater directly as select options it should be value=>label, not repeaterkey=>repeaterdata
rabol
rabolOP2y ago
Sorry... I don't understand
Dan Harrin
Dan Harrin2y ago
check the content of $this->placeholderGroups and compare it to what you would expect select options() to look like they should be string values, not arrays
rabol
rabolOP2y ago
$this->placeholderGroups is a different array of data I have renamed it to placeholderGroupsOptions, but still the same
Dan Harrin
Dan Harrin2y ago
what is inside placeholderGroupsOptions
rabol
rabolOP2y ago
array:3 [▼
0 => array:2 [▶
"id" => "Group_1"
"name" => "Group 1"
]
1 => array:2 [▶
"id" => "Group_2"
"name" => "Group 2"
]
2 => array:2 [▶
"id" => "Group_3"
"name" => "Group 3"
]
]
array:3 [▼
0 => array:2 [▶
"id" => "Group_1"
"name" => "Group 1"
]
1 => array:2 [▶
"id" => "Group_2"
"name" => "Group 2"
]
2 => array:2 [▶
"id" => "Group_3"
"name" => "Group 3"
]
]
the end result should be that if a 'group' is added in the first repeater, then it should be available as a option in the select in the second repeater, but that is step 2 😀 now the placeholderGroupsOptions looks like this:
array:3 [▼
"Group_1" => "Group 1"
"Group_2" => "Group 2"
"Group_3" => "Group 3"
]
array:3 [▼
"Group_1" => "Group 1"
"Group_2" => "Group 2"
"Group_3" => "Group 3"
]
so now I don't get the error, but no values is added to the selelct in the second repeater until I add a new entry in the first repeater
Dan Harrin
Dan Harrin2y ago
but its up to you to populate placeholderGroupsOptions with the repeater items, right?
rabol
rabolOP2y ago
yes but if it can be done 'automaticlly' that would be cool the values in the second select should be the 'name'/'prompt' from the group repeater
Dan Harrin
Dan Harrin2y ago
->options(fn ($get) => collect($get('placeholderGroups'))->pluck('name', 'id')) you could use $this->placeholderGroups, but $get is reccomended
rabol
rabolOP2y ago
that would be awesome... I'll try hmm.. I must be typing something wrong as it does not work. both repeaters are working, but the select in the second repeater does not get the data from the first repeater
Dan Harrin
Dan Harrin2y ago
try $get('../../placeholderGroups') inside the second repeater
rabol
rabolOP2y ago
sorry no
rabol
rabolOP2y ago
rabol
rabolOP2y ago
changed to this: >options(function ($get) { //debug($get); $c = collect($get('../../placeholderGroups'))->pluck('name', 'prompt'); debug($c); return $c; }), and $c contains 3 collections with no items
Dan Harrin
Dan Harrin2y ago
i dont see your placeholderGroups repeater
rabol
rabolOP2y ago
I just found it... one second
->options(fn ($get) => collect($get('../../placeholder_groups'))->pluck('name', 'prompt')),
->options(fn ($get) => collect($get('../../placeholder_groups'))->pluck('name', 'prompt')),
works perfectly Thanks! small issue... when adding a new group, the new 'entry' will have 'null' in either 'name' or 'prompt' until someting is entered. As long as it's 'null' it will throw an error I can simply iterate over the array and remove 'null' but is there a smart way? ->options(fn ($get) => collect($get('../../placeholder_groups'))->pluck('name', 'prompt')->filter()->all()),
Dennis Koch
Dennis Koch2y ago
Sounds like a smart way to me
Want results from more Discord servers?
Add your server