F
Filament13mo ago
ouch

Custom Page -> open modal from code (dispatch)

I have custom page and i need open modal in certain condition. Is there better way than this, cuz i feel like this is terrible. And i bet that there is better way to do it, as well when i click at either of button it loads for 500ms is there way to skip animation?
class ScanProducts extends Page
{
#[Rule('min:3', message: 'Minimální počet znaků 3')]
#[Rule('required',message: 'Čárový kód musí být vyplněn.')]
public $barcode = '';

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('barcode')...
]);
}

public function scan()
{
$product = Item::where('barcode',$this->barcode)->first();
if(!$product && $this->barcode) {
/////// OPENING MODAL HERE
$this->dispatch('open-modal', id: 'create-product');
/*Some other logic*/
}

public function redirectCreateProduct()
{
return $this->redirect( ItemResource::getUrl('create'));
}
public function closeModal()
{
$this->dispatch('close-modal', id: 'create-product');
}
}
class ScanProducts extends Page
{
#[Rule('min:3', message: 'Minimální počet znaků 3')]
#[Rule('required',message: 'Čárový kód musí být vyplněn.')]
public $barcode = '';

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('barcode')...
]);
}

public function scan()
{
$product = Item::where('barcode',$this->barcode)->first();
if(!$product && $this->barcode) {
/////// OPENING MODAL HERE
$this->dispatch('open-modal', id: 'create-product');
/*Some other logic*/
}

public function redirectCreateProduct()
{
return $this->redirect( ItemResource::getUrl('create'));
}
public function closeModal()
{
$this->dispatch('close-modal', id: 'create-product');
}
}
pages blade
...
<x-filament::modal id="create-product" icon="heroicon-o-information-circle">
{{--CONTENT--}}
<x-slot name="footerActions">
<x-filament::button
color="gray"
wire:click="closeModal()"
>
Close
</x-filament::button>
<x-filament::button
wire:click="redirectCreateProduct()"
>
Create
</x-filament::button>
</x-slot>
</x-filament::modal>
<x-filament-actions::modals />
...
<x-filament::modal id="create-product" icon="heroicon-o-information-circle">
{{--CONTENT--}}
<x-slot name="footerActions">
<x-filament::button
color="gray"
wire:click="closeModal()"
>
Close
</x-filament::button>
<x-filament::button
wire:click="redirectCreateProduct()"
>
Create
</x-filament::button>
</x-slot>
</x-filament::modal>
<x-filament-actions::modals />
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server