Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FrogMen's avatar

Render caused problem

I have full page component where a user can buy ticket etc for more persons at once. I store the states in the component in one place for easy handling. I loop the persons, every person can select the price, and discount. The discount select is a custom one used choices.js, because even native select works the designer needs custom styled select. and choices.js looks like on the plan, and its vanilla js.

So the problem comes, when the user first selects the discount, discount calculated, replaced the price with discounted one, but when the user tries to use select to choose nothing or diff. discount, the select instantly closes (js change event calls a php method for calculate...). I added logs to the code parts, and the morphed hook always run, rerenders the choices.js, and this make the select close instantly i think.

I used morphed hook because I saw it in some tutorials to call again the "plugin" after render.

Any idea how to fix that, or how to refactor that the real time calculation functionality remain?

the component:

calling component which is in the persons loop:

<x-choices-optgroup-select 
    :id="'discount-select-' . $index" 
    :options="$discountOptions"
    :selected="$persons[$index]['discount_id'] ?? ''" 
    :index="$index"
/>

the component works if its just sits on the page and renders at page load. You ask why $(document).ready().. DOMContentLoaded doesn't work in here..

0 likes
1 reply
FrogMen's avatar

Okay, what finally worked is this:

  1. put wire:ignore on a parent div not on select
  2. use different hook:
document.addEventListener('livewire:updated', () => {
    initChoices();
});

I should say this solution worked here, not sure you can't use morphed hook in your case

Please or to participate in this conversation.