Closed veronikafouk closed 1 year ago
There are several different approaches you could take, but since you’re working with JS I suggest you hook into the htmx:configRequest
event.
const refreshSearchButton = document.querySelector('.js-search-results-refresh') as HTMLElement;
const bar = document.querySelector('#sprig-estate-search-results') as HTMLElement;
refreshSearchButton?.addEventListener('click', () => {
bar.addEventListener('htmx:configRequest', function(event) {
event.detail.parameters['foo'] = 42;
});
htmx.trigger(bar, 'refresh');
});
An alternative approach would be to use a hidden input field, as explained in https://github.com/putyourlightson/craft-sprig/issues/209#issuecomment-1080468340.
Thank you!!! I decided to go with the htmx:configRequest event and it worked.
Have a nice day. :))
I'm trying to pass data from ts to a sprig component. I found the htmx.trigger() function and tried it. My component is refreshing, but i can't access the data i'm trying to pass. "Foo" is the variable i'm trying to change.
Heres my code ->
Include sprig component:
Inside the sprig component:
And the ts file:
For now it's just a dummy, because i'm trying to find a solution, but in the future i would like to pass the data from a react component to the sprig component.
Thank you in advance. Really love this framework <3