#htmx hx-trigger question
38 messages · Page 1 of 1 (latest)
YOOOOO HTMX MENTIONED !!
You can't, you'd have to call the backend for updates (from your HTMX) and then re-render
yes, didn't see a tag for that.
Please describe example of calling backend for updates ?
You like return (html) or something ?
Well
Someone suggested this:
<div hx-get="/latest_updates" hx-trigger="every 1s">
Nothing Yet!
</div>
Well, it's a pi pico w and what I would like to do is to show the pin state.
The python variable already detects pin state either .value() true or false or .value(0) or .value(1).
So in this case when pin state changes I have a python variable that changes from level="NORMAL" to level="HIGH". Basically pin level detection.
I don't think HTMX is the right thing for that
If you want realtime updates you'd need websockets, HTTP is a pull model (client requests from server) while you can use websockets with the push model (server sends stuff to client)
So while its status pending I just return something like this:
<div hx-get="/jobs/status/JOB_ID" hx-swap="outerHTML" hx-trigger"load delay:3s">
<p> loading stuff ok cool>
</div>
this one reloads itself every 3 seconds in this case and then when the job is completed I display the full card with the job stuff + link to visit the job's page
So once the change in python value occurs I want to see this on screen like a high level float switch that either closes the pin to ground, or opens it.
I have a lot of web simulated stuff on the page, but in reality that was only for learning and simulating the features of the pin state.
I have yet to actually monitor the pin state via web interface. AND without any user interaction or events other then the pin state.
websockets would be the right thing in that case
I guess
I think your right
You could use HTML server-sent events but I find that a bit weird / haven't used it
can you confirm if hx-get or hx-trigger would even be able to actually get the html element change this way ?
Seems to me that it would only get something if the element itself had it's values and data there.
However, if the page did not refresh the data would be the same as it was when I opened it. Not like event onclick that changes the data and updates the innterText etc.
Those event methods are totally different and I can't see how to get the data to the element by a pin state change actually.
Can you confirm if htmx will even be able to do this at all. I mean even with a timed get or trigger etc.
I don't see it doing that if it's not refreshing or getting the data from python.
Your browser would be polling the Python backend every X seconds
if it's not polling the server nothing else will be happening lol
ahhh ok so theoretically it could do it this way.
this ones a bit nicer
thanks for the responses by the way.
since it just replaces itself with the loading state until its finished loading, in your case you would just replace it with the correct value continually
the htmx documetation seems confusing. I have the correct library loaded aka
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
as far as I know I put into the head, but I'm not sure about the syntax.
Documentation shows <div but I assume I can use the hx-trigger call in the element itself like <h3 ..... etc. or whatever ? Or does it need to be in a scrip like javascript functions etc.
This is the line I want to get updated mostly if I can understand syntax I can probably update anything from there.
<h3>LEVEL is <span id="textlevel">{level}</span><h3/>
People typically use divs, haven't ever tried to put stuff on something that's not a dict
The HTMX idea is to send that entire thing down (and not only the level)
{level} is the python variable in the html block of python etc.
So you're also using some templating library with HTMX I guess
in the html block of python etc.
wat
yes,
wat
Line #327-ish for interrupt function and pin state changes based on pin.
https://www.pythonmorsels.com/p/2uqer/
Disregard all that other web based simulator stuff and listeners that is for the web interface simulation etc. Not relevant to pin state really. I will likely get rid of all that except the push notification stuff.
Anyhow level = "NORMAL" pin open.
level ="HIGH" pin closed.
I short the .value() = False or .value()True
etc etc.
ah you just string format them in