question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refresh component B with s-val from component A

See original GitHub issue

Question

Hi Ben, I am trying to build a link which will load an entry into another component. I have a list of entries wich is updated via sprig – just to give you some context. Each list item has a link that should load the given entry into my overlay container.

This is a stripped down version of what I have. When I click the link it loads more entries from my list into the overlay component. But it looks like my link is not passing the entryId to the entryOverlay component. Is it even possible to send a s-val from one component to another? I am sure I am just overlooking something in the docs.

{#-- main --#}
<main>
	{{ sprig('_components/entryList') }}

	{{ sprig('_components/entryOverlay', {}, {
		'id': 'entryOverlay',
	}) }}
</main>

{#-- _components/entryList --#}
{% set entries = craft.entries.section('mySeciton').offset(offset).limit(limit).all() %}

{% for entry in entries %}
	 <a sprig s-target="#entryOverlay" s-val:entry-id="{{entry.id}}">{{ entry.title }}</a>
	 {# limit and offset updated with a revealed trigger #}
{% endfor %}

{#-- _components/entryOverlay --#}
{% set entryId = entryId ?? false %}
{% set entry = craft.entries.id(entryId).one() %}

{% if entry %}
	<p>{{entry.title}}</p>
{% endif %}

So I am basically looking for button that refreshes another component with a new variable.

Additional context

I also tried a different button like this

<button onclick="htmx.trigger('#entryOverlay', 'refresh', {entryId: {{entry.id}}});">{{ entry.title }}</button>

But I it also doesn’t pass the variable.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
pimagocommented, Apr 1, 2022

Cool, that did it. Thanks!

0reactions
bencrokercommented, Mar 31, 2022

Thanks. I think this also prevents the link from sending the hidden input entryId value? It doesn’t seem to work.

Ah right, in that case you can include that input field only.

{{ sprig('_components/entryOverlay', {}, {
    'id': 'entryOverlay',
    's-include': 'input[name=entryId]',
}) }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to refresh a component from another in angular? [closed]
To refresh, or better to say update another component from a different component, we can use the concept of Observables and Subject (which ......
Read more >
apex - How to refresh one component from another ...
I have Component B that has a lightining-button which on click shows a Modal for editing the same record that is displayed in...
Read more >
Refresh Component | JET Developer Cookbook - Oracle
This demo shows the behavior of an editable form control when refresh method is called. Example 1: Username field has deferred error when...
Read more >
PRIME H610M-E D4|Motherboards|ASUS Global
PRIME H610M-E D4 Intel® H610 (LGA 1700) micro ATX motherboard features PCIe 4.0, 32Gbps M.2 slot, Realtek 1 Gb Ethernet, DisplayPort, HDMI, D-Sub, ......
Read more >
Angular: Reload/Refresh a Component or Entire Application ...
An Angular tutorial on how to reload/refresh a single component or the entire application and reuse the logic across multiple components.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found