F
Filamentβ€’12mo ago
eazy

Actions error in Infolist

I have the a infolist with 2 cards which are conditionally displayed. They both have different actions. When I do the start_configuration action the card gets hidden and the other card gets displayed. But when I want to click the close_configuration action I get a javascript error in my console. The action only works when I refresh, how can I fix this?
Solution:
@pboivin I just updated to the newest livewire beta (3.0.7) and it seems to be fixed so I'm closing this issue for now πŸ˜„
Jump to solution
8 Replies
eazy
eazyβ€’12mo ago
<?php
public
function machineInfoList(Infolist $infolist): Infolist
{
return $infolist
->record($this->machine)
->schema([
Card::make()
->schema([
TextEntry::make('activeMachineConfiguration.batch.code'),
TextEntry::make('activeMachineConfiguration.started_at'),
Actions::make([
Action::make('close_configuration')
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
$closeMachineConfiguration($record->activeMachineConfiguration);
})
]),
])->hidden($infolist->record?->activeMachineConfiguration === null),
Card::make()
->schema([
TextEntry::make('text')
->hiddenLabel()
->size('lg')
->weight('bold'),
Actions::make([
Action::make('start_configuration')
->form([
Select::make('batch')
->label(__('batches.batch'))
->options(Batch::all()->pluck('code', 'id'))
->required(),
])
->action(function (array $data, StartNewConfigurationForMachine $startNewConfigurationForMachine) {
$startNewConfigurationForMachine($data, $this->machine);
})
]),
])->hidden($infolist->record?->activeMachineConfiguration !== null),
]);
}
<?php
public
function machineInfoList(Infolist $infolist): Infolist
{
return $infolist
->record($this->machine)
->schema([
Card::make()
->schema([
TextEntry::make('activeMachineConfiguration.batch.code'),
TextEntry::make('activeMachineConfiguration.started_at'),
Actions::make([
Action::make('close_configuration')
->requiresConfirmation()
->action(function (Machine $record, array $arguments, CloseMachineConfiguration $closeMachineConfiguration, Action $action) {
$closeMachineConfiguration($record->activeMachineConfiguration);
})
]),
])->hidden($infolist->record?->activeMachineConfiguration === null),
Card::make()
->schema([
TextEntry::make('text')
->hiddenLabel()
->size('lg')
->weight('bold'),
Actions::make([
Action::make('start_configuration')
->form([
Select::make('batch')
->label(__('batches.batch'))
->options(Batch::all()->pluck('code', 'id'))
->required(),
])
->action(function (array $data, StartNewConfigurationForMachine $startNewConfigurationForMachine) {
$startNewConfigurationForMachine($data, $this->machine);
})
]),
])->hidden($infolist->record?->activeMachineConfiguration !== null),
]);
}
This is the error in my console:
Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I've tried replacing the hidden with style display: none; so that the component stays rendered in the background But that also doesn't seem to work I think it has something to do with the ->requiresConfirmation() modal. Because when I switch from the close_action to the start_configuration it seems to work Morning, this still doesn't seem to be working. I was wondering if I'm doing something wrong or if its a bug
Patrick Boivin
Patrick Boivinβ€’12mo ago
I'm also getting this error in a different context (with the Builder field). I'm trying to look into it.
eazy
eazyβ€’12mo ago
Okay, so its not something in my code πŸ˜…
Patrick Boivin
Patrick Boivinβ€’12mo ago
Maybe not... probably not πŸ˜‚
eazy
eazyβ€’12mo ago
Haha okay thanks, I'll wait if you find something πŸ™‚
Patrick Boivin
Patrick Boivinβ€’12mo ago
@eazyurk Something you can try is running off of Livewire's main branch (until the next beta is tagged). In your composer.json :
"livewire/livewire": "dev-main as 3.0",
"livewire/livewire": "dev-main as 3.0",
Then run php artisan optimize:clear and make sure to clear the browser's cache.
Solution
eazy
eazyβ€’12mo ago
@pboivin I just updated to the newest livewire beta (3.0.7) and it seems to be fixed so I'm closing this issue for now πŸ˜„
eazy
eazyβ€’12mo ago
Thx I was already looking how to do it haha πŸ™‚