Dynamic CheckboxList can't track state

I have a wizard with the first step that includes the user uploading a primary file and one or more lookup files. On that step's afterValidation method, I analyze the files and set a state property as well as a Livewire component value:
->afterValidation(function (Set $set, $state) {
$mappings = CreateJoinMergeMappings::create(
primaryFile: Arr::first($state['primary_file']),
lookupFiles: $state['lookup_files']
);
$set('mappings', $mappings['mappings_template']);
$this->headersByFile = $mappings['headers_by_file'];
})
->afterValidation(function (Set $set, $state) {
$mappings = CreateJoinMergeMappings::create(
primaryFile: Arr::first($state['primary_file']),
lookupFiles: $state['lookup_files']
);
$set('mappings', $mappings['mappings_template']);
$this->headersByFile = $mappings['headers_by_file'];
})
I have a wizard step that uses the mappings in a form repeater and it works perfectly. However, I want to dynamically create another step's schema that includes two or more checkbox lists. In the step's schema, I'm passing a closure. Here's the step:
Step::make('Output Fields')
->columns(4)
->schema(
function () {
$checklists = [];
foreach ($this->headersByFile as $file => $headers) {
$baseFile = Str::before($file, '.');
$options = collect($headers)->mapWithKeys(fn($header) => [$header => $header])->toArray();
$checklists[] = CheckboxList::make($baseFile)
->label($baseFile)
->options($options);
}
return $checklists;
}
)
Step::make('Output Fields')
->columns(4)
->schema(
function () {
$checklists = [];
foreach ($this->headersByFile as $file => $headers) {
$baseFile = Str::before($file, '.');
$options = collect($headers)->mapWithKeys(fn($header) => [$header => $header])->toArray();
$checklists[] = CheckboxList::make($baseFile)
->label($baseFile)
->options($options);
}
return $checklists;
}
)
The checkbox lists render properly but when selecting one of the options, all options in that checkbox list are selected. This leads me to believe there is something in my code preventing the checkbox list from properly tracking it's state. What am I doing wrong? Thanks
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server