https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • t

    tall-dinner-62086

    09/23/2022, 9:41 AM
    I may have been overly optimistic about idiomorph
  • t

    tall-dinner-62086

    09/23/2022, 9:41 AM
    Or just misunderstood it completely
  • p

    proud-librarian-99598

    09/23/2022, 9:42 AM
    https://stackoverflow.com/questions/18679982/follow-redirect-302-in-xmlhttprequest seems to suggest that you need to do something explicit for following the redirect, but maybe that changed in recent browsers?
  • p

    proud-librarian-99598

    09/23/2022, 9:43 AM
    According to https://stackoverflow.com/questions/228225/prevent-redirection-of-xmlhttprequest it should be possible by using the fetch API
  • t

    tall-dinner-62086

    09/23/2022, 9:44 AM
    Htmx doesn't use the fetch api due to ie11 compatibility
  • s

    stocky-dentist-80693

    09/23/2022, 9:44 AM
    There's been some previous discussion about it over on GitHub - https://github.com/bigskysoftware/htmx/issues/632
  • p

    proud-librarian-99598

    09/23/2022, 9:48 AM
    I don't care about ie11, but I know @mysterious-toddler-20573 does 🙂
  • p

    proud-librarian-99598

    09/23/2022, 9:49 AM
    So it seems I am the first one that cares about proper handling of htmx requests when the user is no longer authorized?
  • t

    tall-dinner-62086

    09/23/2022, 10:01 AM
    When a user is not authorized to do an action, I return 403 and HX-Redirect away.
  • s

    stocky-dentist-80693

    09/23/2022, 10:02 AM
    if (not_logged_in() && is_htmx()) { header("HX-Refresh"); exit(); }
    ?
  • p

    proud-librarian-99598

    09/23/2022, 10:12 AM
    Sweet, I managed to return a 403 when it is an htmx request with
    HX-Refresh: true
    and now everything works
  • p

    proud-librarian-99598

    09/23/2022, 10:12 AM
    Thanks @tall-dinner-62086 and @stocky-dentist-80693 for helping me out!
  • p

    polite-oil-80202

    09/23/2022, 10:50 AM
    Hi ! I'm hitting an issue with cache and I'm not sure how to solve it. Here is my use case : I load an employee list page with 10 default employees and a live search with htmx. When I search, the default live search results replaces the default employees list with the results. If I click on a result I go to the details page. From the details page, if I click the back button on the browser, I have my last employees list page with filtered results from the cache and I was expecting to have a fresh new page with the default employees. I'm doing something wrong with htmx, but I don't understand what.
  • t

    tall-dinner-62086

    09/23/2022, 10:53 AM
    I would expect to see exactly what was on the screen before I clicked a result when I press the back button
  • p

    polite-oil-80202

    09/23/2022, 10:56 AM
    It's not exactly what was on the screen, the search input is empty whereas it contained the query before.
  • t

    tall-dinner-62086

    09/23/2022, 10:57 AM
    hmm
  • t

    tall-dinner-62086

    09/23/2022, 10:57 AM
    I mean, pressing the back button shouldn't make a new request
  • p

    polite-oil-80202

    09/23/2022, 11:00 AM
    Which is the case right now, but I need to refresh the screen on back
  • t

    tall-dinner-62086

    09/23/2022, 11:02 AM
    Sorry I'm all over the place right now. Are you using
    hx-push-url
    ?
  • p

    polite-oil-80202

    09/23/2022, 11:03 AM
    Going from employees list to employee's details is a basic anchor tag
  • t

    tall-dinner-62086

    09/23/2022, 11:06 AM
    You could try using the htmx history support stuff to handle history better. I'm not sure there's a way to force a page refresh only when the user presses the back button
  • v

    victorious-addition-87840

    09/23/2022, 11:36 AM
    how can i go about using htmx with shared layout and the edge template?
  • v

    victorious-addition-87840

    09/23/2022, 11:37 AM
    right now i need to replace entire page, which is the same as reload but without the flicker and stuff
  • v

    victorious-addition-87840

    09/23/2022, 11:37 AM
    i dont think i am doing it right
  • g

    gifted-appointment-5037

    09/23/2022, 11:38 AM
    I've written the TodoMVC app with my new framework https://www.npmjs.com/package/htmxx ... got everything working except being able to delete an item from the UI once the DELETE response returns and also clearing the text field after creating a new todo. Both cases use the approach
    _="on htmx:afterOnLoad ..."
    The input clearing code is
    Copy code
    <form
      hx-post="/todos"
      hx-target="#todo-list"
      hx-swap="afterbegin"
      _="on htmx:afterOnLoad set #txtTodo.value to ''"
    >
      <input
        class="new-todo"
        id="txtTodo"
        name="todo"
        placeholder="What needs to be done?"
        autofocus=""
      />
    </form>
    and the row deleting code is
    Copy code
    <button
      class="destroy"
      hx-delete="/todos/{{id}}"
      _="on htmx:afterOnLoad remove #todo-{{id}}"
    ></button>
    What have I missed? (there's no errors in the console)
  • b

    broad-pencil-64390

    09/23/2022, 11:43 AM
    A bit of htmx spotted on djangocon keynote
  • m

    mysterious-toddler-20573

    09/23/2022, 12:55 PM
    You would want to use an hx-get, hx-push-url and an hx-include (hx-include on a boosted link may work too, I'd need to test)
  • m

    mysterious-toddler-20573

    09/23/2022, 12:56 PM
    Everyone is waiting for this!
  • m

    mysterious-toddler-20573

    09/23/2022, 12:58 PM
    do you have hyperscript installed? It's a separate library from htmx.
  • g

    gifted-appointment-5037

    09/23/2022, 1:04 PM
    aah no ... didn't realise that. Immediately fixed 🙂 Thanks SO MUCH!! Okay so that leads me to my next question. Is there a way to do dynamic classes or attributes using htmx? (e.g. an active state on navigation element) Or do I have to return the HTML for it and do an OOB-SWAP?
1...834835836...1146Latest