usernotnull / tall-toasts

A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS 🔥🚀
MIT License
537 stars 32 forks source link

When dispatching toast on livewire component with form, toast is shown after validation (even if put before validation) #546

Closed BoGnY closed 3 weeks ago

BoGnY commented 3 weeks ago

Description

I have a form saving that require some seconds, so I try to put a info toast to inform user that I'm saving it... But the toast appears always after validation is done, even if I put the toast dispatch before starting validation..

Not sure if I'm doing something wrong 😞

To Reproduce

  1. on blade I call save function with wire:click
  2. on livewire component in save function I put toast dispatch, form saving, then redirect
  3. WireToast trait is present

Expected behavior

Toast dispatching was done when called, so before validation.

Screenshots

image

Additional context

I've tried three different code type, same result. As shown, toast dispatch is put before validation, ($this->form->save() call $this->validate() in livewire form component), but toast is shown only when validation is completed

usernotnull commented 3 weeks ago

👋 hi

Alternate between push and pushOnNextPage methods.

BoGnY commented 3 weeks ago

Hi, I've tried, but with pushOnNextPage the toast is shown only when refreshed, and is refreshed only if validation is ok, and this is not the case, because I need info toast even if validation fails.

The interested line is the 53, not the 39, sorry I didn't specify.

BoGnY commented 3 weeks ago

I've made a small video..

https://github.com/usernotnull/tall-toasts/assets/11542801/64e618b3-9c57-4bc3-94bf-5fda5050e606

As shown, "Salvato" appears with $this->dispatch('asset-saved') (line 58) so after validation and saving, but together with toast which is put before validation..

BoGnY commented 3 weeks ago

Closed as is not a toast's bug but probably a livewire's bug: https://github.com/livewire/livewire/discussions/8598