form not rendering until 2nd click

I have a form that's not rendered until the user selects an item from a list, be design. Once an item is selected the form should load and be available when the user clicks another button within the item. The form isn't loaded on the initial button click, it's just a blank modal with only the heading and the close button, no form. If I close out of the modal, then click on another item in the $recentRecs list, the form loads correctly. In the list:
@foreach ($recentRecs as $rec)
<div class="" wire:key="recent-rec-{{ $rec['id'] }}">
<x-filament::section class="cursor-pointer" wire:click="loadRecent({{ $rec['id'] }})">...
@foreach ($recentRecs as $rec)
<div class="" wire:key="recent-rec-{{ $rec['id'] }}">
<x-filament::section class="cursor-pointer" wire:click="loadRecent({{ $rec['id'] }})">...
public function mount(int $locationId): void
{
$this->form->fill();
$this->createNewForm->fill();
}

public function loadRecent($id)
{
$this->selectedRecId = $id;
$this->salesRec = SalesReconciliation::with('items')->find($id);
$this->items = $this->getReportData();
$this->setVars();
}

public function setVars()
{
$itemCollection = collect($this->items);
$this->data = $itemCollection->mapWithKeys(function ($item) {
return [$item['account_ref_id'] => $this->toCurrency($item['sms_amount'])];
})->toArray();
//can dd $this->data here and I get the expected array.
$this->form->fill($this->data);

...
}

public function getForms(): array
{
return [
'createNewForm',
'form'
];
}
public function mount(int $locationId): void
{
$this->form->fill();
$this->createNewForm->fill();
}

public function loadRecent($id)
{
$this->selectedRecId = $id;
$this->salesRec = SalesReconciliation::with('items')->find($id);
$this->items = $this->getReportData();
$this->setVars();
}

public function setVars()
{
$itemCollection = collect($this->items);
$this->data = $itemCollection->mapWithKeys(function ($item) {
return [$item['account_ref_id'] => $this->toCurrency($item['sms_amount'])];
})->toArray();
//can dd $this->data here and I get the expected array.
$this->form->fill($this->data);

...
}

public function getForms(): array
{
return [
'createNewForm',
'form'
];
}
<x-slot name="headerEnd">

<x-filament::modal slide-over id="sales" width="xl">

{{ $this->form }}

<x-slot name="footer">
<button type="button" wire:click="$dispatch('close-modal', { id: 'sales'} )">Close</button>
</x-slot>
</x-filament::modal>
</x-slot>
<x-slot name="headerEnd">

<x-filament::modal slide-over id="sales" width="xl">

{{ $this->form }}

<x-slot name="footer">
<button type="button" wire:click="$dispatch('close-modal', { id: 'sales'} )">Close</button>
</x-slot>
</x-filament::modal>
</x-slot>
1 Reply
Jon Mason
Jon MasonOP5mo ago
no console errors or anything. I think it has to do with a dynamic form schema I'm trying to use. The form schema will change depending on which item is selected in the list...not sure why it won't load the schema the first time around and then will after a different item is selected.
Want results from more Discord servers?
Add your server