F
Filament11mo ago
Oumaima

open modal with js

I have created custom page which has a modal , I want to open the modal using js after an event , but I failed , how can I do that using js please , I searched but I didn't get it
No description
21 Replies
Oumaima
Oumaima11mo ago
heeelp! @Dennis Koch
awcodes
awcodes11mo ago
Please don't tag people.
awcodes
awcodes11mo ago
Laravel
Events | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Oumaima
Oumaima11mo ago
I apologize , I didn't know that I shouldn't tag anyone , and thank you for your effort
Dennis Koch
Dennis Koch11mo ago
Then please read the server #✅┊rules 😉
LeandroFerreira
LeandroFerreira11mo ago
<x-filament-panels::page>
<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>

@push('scripts')
<script>
document.addEventListener('livewire:initialized', () => {

//dispatch the modal...
@this.dispatch('open-modal', {
id: 'myModal'
});
});
</script>
@endpush
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>

@push('scripts')
<script>
document.addEventListener('livewire:initialized', () => {

//dispatch the modal...
@this.dispatch('open-modal', {
id: 'myModal'
});
});
</script>
@endpush
</x-filament-panels::page>
Oumaima
Oumaima11mo ago
it didn't work for me , I don't know why
LeandroFerreira
LeandroFerreira11mo ago
what is the issue?
Oumaima
Oumaima11mo ago
the modal do not open
LeandroFerreira
LeandroFerreira11mo ago
does it work?
<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>
<x-filament::button @click="$dispatch('open-modal', {id: 'myModal'})">Open modal</x-filament::button>
<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>
<x-filament::button @click="$dispatch('open-modal', {id: 'myModal'})">Open modal</x-filament::button>
Oumaima
Oumaima11mo ago
I don"t want to open it using a button , I want it to open whan I scann a qr code
LeandroFerreira
LeandroFerreira11mo ago
yep, I know, but this works?
Oumaima
Oumaima11mo ago
you mean with button
LeandroFerreira
LeandroFerreira11mo ago
yes
Oumaima
Oumaima11mo ago
no i tried it now , it does not work
LeandroFerreira
LeandroFerreira11mo ago
console errors?
Oumaima
Oumaima11mo ago
I'm sorry for losing your time , I just want to figure out what's the problem and how to resolve it nothing
LeandroFerreira
LeandroFerreira11mo ago
if you are running this
<x-filament-panels::page>

<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>
<x-filament::button @click="$dispatch('open-modal', {id: 'myModal'})">Open modal</x-filament::button>

</x-filament-panels::page>
<x-filament-panels::page>

<x-filament::modal id="myModal">
<div>
Content...
</div>
</x-filament::modal>
<x-filament::button @click="$dispatch('open-modal', {id: 'myModal'})">Open modal</x-filament::button>

</x-filament-panels::page>
It was supposed to work. It is a simple modal test
Oumaima
Oumaima11mo ago
I cleared the cache and all , this one works now but this no
LeandroFerreira
LeandroFerreira11mo ago
without @push('scripts') ? What is the output? What about this?
<script>
document.addEventListener('livewire:initialized', () => {
console.log('initialized!');
});
</script>
<script>
document.addEventListener('livewire:initialized', () => {
console.log('initialized!');
});
</script>
You need to check the code step by step to find the issue..
Oumaima
Oumaima11mo ago
I removed document.addEventListener('livewire:initialized', () => { }); and it worked I did just this line <script> @this.dispatch('open-modal', { id: 'myModal' });</script> thank you so much sir
Want results from more Discord servers?
Add your server
More Posts