presleyd / alpinejs-select

85 stars 19 forks source link

How can i refresh the data passed to the compoenents ? #16

Open BenOussama180 opened 1 year ago

BenOussama180 commented 1 year ago

i have made a dropdown of projects with this select components, but i have an input up top that adds a projects in case you want to create a new one , so upon creation i want to refresh the data so the dropdoown would have the new project that i just created without having to refresh the page

presleyd commented 1 year ago

Are you using Livewire?

On Fri, Nov 18, 2022 at 9:10 AM Oussama Bendriss @.***> wrote:

i have made a dropdown of projects with this select components, but i have an input up top that adds a projects in case you want to create a new one , so upon creation i want to refresh the data so the dropdoown would have the new project that i just created without having to refresh the page

— Reply to this email directly, view it on GitHub https://github.com/presleyd/alpinejs-select/issues/16, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACY6IXHKCT6KA54APG6UDF3WI6E5TANCNFSM6AAAAAASEQ7LXY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

BenOussama180 commented 1 year ago

… Yes TALL stack

BenOussama180 commented 1 year ago

image this is my render function ( where i pass the projects the the blade ) image this is the function that handles project creation in the same livewire component image and this is the blade component

presleyd commented 1 year ago

Hrmmm. I don't immediately see a problem. But I have never passed variables to blade when using livewire using compact(). Instead of passing cart, projects, and wishlist to the blade, if you make them a public variable it should do the same thing then you can use $this->projects = Project::where(...) inside of render. Putting them in render isn't the best option overall because that will be called on every single livewire round trip. I'd put the ones that won't change in mount() and the ones that will change I'd move to their own function and just call that function in the creatProject() function

On Fri, Nov 18, 2022 at 10:49 AM Oussama Bendriss @.***> wrote:

[image: image] https://user-images.githubusercontent.com/81111919/202745091-208d6b6a-b97a-4eca-b1ff-1d2b947e27a2.png this is my render function ( where i pass the projects the the blade ) [image: image] https://user-images.githubusercontent.com/81111919/202745183-1d57a63a-c995-4292-a98d-fcf4e9c23e94.png this is the function that handles project creation in the same livewire component [image: image] https://user-images.githubusercontent.com/81111919/202745273-78602999-3310-455b-90ef-24643c44cb09.png and this is the blade component

— Reply to this email directly, view it on GitHub https://github.com/presleyd/alpinejs-select/issues/16#issuecomment-1320203377, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACY6IXDD4JHPZTRDUYUK3A3WI6QP5ANCNFSM6AAAAAASEQ7LXY . You are receiving this because you commented.Message ID: @.***>

BenOussama180 commented 1 year ago

i tried making the projects variable in the mount didnt work , ill try other stuff

BenOussama180 commented 1 year ago

Render function : image Create Projet Function : image Select component : image Create Project markup : image UI : image

NB : everything is on the same livewire component ! so when i create a project in the input above, i dont find the new prooject created inside the dropdoown, even tho i re-run the project query inside the createProject function

BenOussama180 commented 1 year ago

@presleyd any help on how can i achieve refreshing data in the dropdown ? i did a print_r($projects->sortByDesc('created_at')->first()) in my view to see ifthe data gets refreshed after creating a project , it well did , but the dropdown is not refreshed

presleyd commented 1 year ago

It's been a while since I used my own creation here so I had to remember. The 'data' prop is not currently reactive that way. You could modify the data prop to be entangled to make that happen or fire an emit.

On Mon, Nov 21, 2022 at 8:32 AM Oussama Bendriss @.***> wrote:

@presleyd https://github.com/presleyd any help on how can i achieve refreshing data in the dropdown ? i did a print_r($projects->sortByDesc('created_at')->first()) in my view to see ifthe data gets refreshed after creating a project , it well did , but the dropdown is not refreshed

— Reply to this email directly, view it on GitHub https://github.com/presleyd/alpinejs-select/issues/16#issuecomment-1322071015, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACY6IXDVRPBLYAUDBPUOYKLWJN2V7ANCNFSM6AAAAAASEQ7LXY . You are receiving this because you were mentioned.Message ID: @.***>

BenOussama180 commented 1 year ago

@presleyd doo u mean dispatch a browser event using livewire when a new project is added & catch it in the AlpineSelect Init ? i dont get what should i do exactly in the AlpineSelect() ^^