livewire with table inside form: now the form is not saving

Hi! I have a livewire compoenent that starting from a recor di displaying a table with some options that are selectable:
class ListExhibitions extends Component implements HasForms, HasTable
{
use InteractsWithForms;
use InteractsWithTable;

public Winery $winery;

public function mount(Winery $winery): void
{
$this->winery = $winery;
}

public function table(Table $table): Table
{
return $table
->recordClasses("padding-top-0")
->query(Exhibition::query()->where('active',1))
->columns([
Tables\Columns\TextColumn::make('country')->sortable(),
Tables\Columns\CheckboxColumn::make('AC')
->state(function (Exhibition $record): bool {
return $record->wineries->contains($this->winery) ? true : false;
})
->updateStateUsing(function (Exhibition $record, $state) {
if ($state) {
$record->wineries()->attach($this->winery->id);
} else {
$record->masterclass ? $record->masterclass->wineries()->detach($this->winery->id) : "";
$record->wineries()->detach($this->winery->id);
}
})
->label('P'),
]);
}
public function render(): View
{
return view('livewire.exhibitions.list-exhibitions');
}
}
class ListExhibitions extends Component implements HasForms, HasTable
{
use InteractsWithForms;
use InteractsWithTable;

public Winery $winery;

public function mount(Winery $winery): void
{
$this->winery = $winery;
}

public function table(Table $table): Table
{
return $table
->recordClasses("padding-top-0")
->query(Exhibition::query()->where('active',1))
->columns([
Tables\Columns\TextColumn::make('country')->sortable(),
Tables\Columns\CheckboxColumn::make('AC')
->state(function (Exhibition $record): bool {
return $record->wineries->contains($this->winery) ? true : false;
})
->updateStateUsing(function (Exhibition $record, $state) {
if ($state) {
$record->wineries()->attach($this->winery->id);
} else {
$record->masterclass ? $record->masterclass->wineries()->detach($this->winery->id) : "";
$record->wineries()->detach($this->winery->id);
}
})
->label('P'),
]);
}
public function render(): View
{
return view('livewire.exhibitions.list-exhibitions');
}
}
This component is working fine, it's attaching e detaching record as soon as the checkboxes are clicked. The problem is that if I put this livewire componet into a form... You cannot save the form anymore: clicking the save button is doing anything. Cancel button is working. I need help Thank you!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server