Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Use In Mount Method #119

Open
kylekanderson opened this issue Apr 7, 2023 · 5 comments
Open

Can't Use In Mount Method #119

kylekanderson opened this issue Apr 7, 2023 · 5 comments

Comments

@kylekanderson
Copy link

I have some use cases where I'd like to use $this->alert() in the mount() method of my component. This doesn't appear to be supported currently - are there any plans to support this in the future?

@kylekanderson
Copy link
Author

Note: the $this->flash() method works as expected in the mount() method. However, it seems the $this->alert() and $this->confirm() methods do not.

I have found that removing this return; statement enabled the $this->alert() and $this->confirm() methods to work:

Of course, I'm not sure what the repercussions are elsewhere of removing that line.

@WorthLMS
Copy link

I believe this could be easily changed.. .the return seems to just stop it from doing the Flash portion...

this could easily be adjusting to a compact if

$isFlash ? session('flash stuff...') : $this->dispatchBrowserEvent('...stuff...');

completely removing the return;

@WorthLMS
Copy link

Unfortunately, the session took precedence, if the return is removed... so the reason you saw the alert, was because it was running as session flash, and not a dispatched alert... wrapping the session in an else, prevents the alert from showing... so it really worked as a session flash message in Mount and not an actual dispatched alert... :'( wish this worked

@WorthLMS
Copy link

I'm assuming this doesn't work for alert, because the page hasn't really been viewed yet, thus there is no javascript to listen and run the alert... the only thing I can think of, is to somehow use it as a session flash value without actually redirecting...

@WorthLMS
Copy link

Note: the $this->flash() method works as expected in the mount() method. However, it seems the $this->alert() and $this->confirm() methods do not.

I have found that removing this return; statement enabled the $this->alert() and $this->confirm() methods to work:

Of course, I'm not sure what the repercussions are elsewhere of removing that line.

I believe we can use wire:init to perform an action once the page has been viewed, and then update information... going to test this theory out and see what happens :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants