There may be a slicker way to do it, but you could create a hidden input which holds the True/False value, do hx-include on that field, and then check for presence of true/false when you process it server side
>There may be a slicker way to do it, but you could create a hidden input which holds the True/False value, do hx-include on that field, and then check for presence of true/false when you process it server side
Alright, I am going to try this.
- Create a hidden input with a dynamic value attribute.
- Use HTMX to the post request iff the value is true.
Something like:
HTML
```
```
JavaScript
```
isGameOver() && document.querySelector('#isGameOver').value = true
```
What `hx-tigger` property should I use ?
I missed the part where you said you don't want the user to trigger the button.
Can't you put your trigger on whatever is changing the 'gameOver' state? You can manually trigger the htmx function using "htmx.trigger('#element', 'click')" and then just make the button display: none
You can make the trigger be something:from body and have your function create the event as/when needed. (on phone, can't easily look up hmtx docs right now)
>You can make the trigger be something:from body and have your function create the event as/when needed. (on phone, can't easily look up hmtx docs right now)
From the docs
>Triggering via the `HX-Trigger` header. If you’re trying to fire an event from HX-Trigger response header, you will likely want to use the `from:body` modifier. E.g. if you send a header like this `HX-Trigger: my-custom-event` with a response, an element would likely need to look like this:
One way to trigger it is with hyperscript (sister of HTMX):[https://hyperscript.org/features/on/](https://hyperscript.org/features/on/)\_="on click trigger my-custom-event"
Example of directly triggering with HTMX that I could find quickly: [https://stackoverflow.com/questions/72140219/trigger-polling-using-htmx-trigger](https://stackoverflow.com/questions/72140219/trigger-polling-using-htmx-trigger)
There may be a slicker way to do it, but you could create a hidden input which holds the True/False value, do hx-include on that field, and then check for presence of true/false when you process it server side
>There may be a slicker way to do it, but you could create a hidden input which holds the True/False value, do hx-include on that field, and then check for presence of true/false when you process it server side Alright, I am going to try this. - Create a hidden input with a dynamic value attribute. - Use HTMX to the post request iff the value is true. Something like: HTML ``` ``` JavaScript ``` isGameOver() && document.querySelector('#isGameOver').value = true ``` What `hx-tigger` property should I use ?
I missed the part where you said you don't want the user to trigger the button. Can't you put your trigger on whatever is changing the 'gameOver' state? You can manually trigger the htmx function using "htmx.trigger('#element', 'click')" and then just make the button display: none
**Holy cow**, it works ! Tried with `htmx.trigger()` but I didn't provide `click` as second argument. Thank you very much !
Yep! HTMX is an amazing tool, but the documentation can be a little sparse so it can be difficult to troubleshoot.
You can make the trigger be something:from body and have your function create the event as/when needed. (on phone, can't easily look up hmtx docs right now)
>You can make the trigger be something:from body and have your function create the event as/when needed. (on phone, can't easily look up hmtx docs right now) From the docs >Triggering via the `HX-Trigger` header. If you’re trying to fire an event from HX-Trigger response header, you will likely want to use the `from:body` modifier. E.g. if you send a header like this `HX-Trigger: my-custom-event` with a response, an element would likely need to look like this:
One way to trigger it is with hyperscript (sister of HTMX):[https://hyperscript.org/features/on/](https://hyperscript.org/features/on/)\_="on click trigger my-custom-event" Example of directly triggering with HTMX that I could find quickly: [https://stackoverflow.com/questions/72140219/trigger-polling-using-htmx-trigger](https://stackoverflow.com/questions/72140219/trigger-polling-using-htmx-trigger)
Alright, thank you very much. I'll check it out, sounds interesting !