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

[LiveComponent] How to target the "__invoke" action in data-loading attribute? #1738

Open
gremo opened this issue Apr 15, 2024 · 1 comment

Comments

@gremo
Copy link
Contributor

gremo commented Apr 15, 2024

In my component, I have the following actions:

  • quantityUp which is invoked by the "plus" button
  • quantiyDown which is invoked by the "minus" button

image

When one of this two actions are called, I need to refresh the price smoothly, and this is accomplished adding "opacity-50" class:

<p
  class="font-mono transition-opacity duration-200"
  data-loading="action(quantityUp)|action(quantityDown)|addClass(opacity-50)"
>
  <!-- Computed total price -->
</p>

This works OK.

Now, when user manually type "43" in the quantity field, component is re-rendered without calling any specific action. Of course the "opacity-50" won't be added, because right now I'm targeting the two specific actions (quantityUp and quantiyDown).

Question: is there a way to also target the default __invoke action (that is, the component re-render) in addition to quantityUp and quantiyDown?

Bonus question: the "mic" button will grab user voice, set a value for an hidden field and triggers a re-render as the field correclty dispatch the change event. Eventually the "opacity-50" will be added too, but it shouldn't be. Is there any way to prevent this behaviour?

@gremo gremo changed the title How to target the "__invoke" action in data-loading attribute? [LiveComponent] How to target the "__invoke" action in data-loading attribute? Apr 15, 2024
@smnandre
Copy link
Collaborator

Question: is there a way to also target the default __invoke action (that is, the component re-render) in addition to quantityUp and quantiyDown?

The default action is called "$render" (with the $) but i'm not sure it will work here... could you try and tell me :)

You also can use model changes to trigger the data-loading instructions: that may help you add custom behaviours

https://symfony.com/bundles/ux-live-component/current/index.html#targeting-loading-when-a-specific-model-changes

Bonus question: [...]

Hmm not sure i follow .. do you want opacity-50 or you don't want opacity-50 ? :)

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