https://htmx.org logo
Join Discord
Powered by
# alpine-htmx
  • g

    gorgeous-airport-54386

    05/06/2023, 3:38 PM
    please
  • g

    gorgeous-airport-54386

    05/06/2023, 3:38 PM
    i don't want to learn to draw properly
  • q

    quick-garage-13170

    05/08/2023, 2:14 PM
    Is it a good idea to build a multiselect search that queries the db for results in HTMX/Alpine? I'm having a hard time building this in a good way because I need to preserve the state of what has already been selected

    https://cdn.discordapp.com/attachments/931549069141225613/1105135715941101608/iu.png▾

  • q

    quick-garage-13170

    05/08/2023, 2:28 PM
    (Pretend the reference picture has a search bar 🙂
  • b

    bitter-machine-55943

    05/08/2023, 2:35 PM
    Picture is blank for me
  • q

    quick-garage-13170

    05/08/2023, 2:41 PM
    Here is a better picture. The o is the search field

    https://cdn.discordapp.com/attachments/931549069141225613/1105142381206061076/image.png▾

  • s

    shy-zebra-22292

    05/08/2023, 3:55 PM
    I think best would be -- send all the selected ones (selected_items_list) to the Backend and then when you render the list I don't know what language you use for Backend so.. here is generic example
    Copy code
    for each ( db_results as db_result ) 
        if (db_result.name is in selected_items_list) 
           display checkmark + db_result.name
        else 
           display empty checkmark + db_result.name
  • g

    gentle-salesclerk-37089

    05/08/2023, 6:51 PM
    are you handling injection attacks?
  • q

    quick-garage-13170

    05/08/2023, 7:05 PM
    Thanks for taking some time to help. The backend part makes sense. I was struggling with storing the tags that were already selected on the frontend. I'm going to see if I can put the hx-vals of the tags that are already selected into each search result. Then I can update the lower div content when a search result is clicked
  • r

    refined-waiter-90422

    05/08/2023, 7:08 PM
    All user input goes through html entity escaping upon input, and again before it hits the database, so doing it again would be a 3rd sanity check, lol. Not necessary.
  • s

    shy-zebra-22292

    05/08/2023, 7:08 PM
    by the way you can make a POST/GET request with a list of values... like so:
    Copy code
    <input type="checkbox" name="animal[]" value="Cat" />
    <input type="checkbox" name="animal[]" value="Dog" />
    <input type="checkbox" name="animal[]" value="Bear" />
    and hx-include the whole
    <form>
    note the name is the same and ends with
    []
    like
    animal[]
    on the backend you will receive this as a list in a single "property"/"variable". in php that would be something like
    $_POST['animal']
    I can imagine Node.js/Express would be
    req.body.animal
    (again, an array of animal names) etc.
  • r

    refined-waiter-90422

    05/08/2023, 7:19 PM
    personally I feel like escaping on the way in is the only way to be sure there wont be some exploit on some other tool/app using that database that doesn't happen to be using jinja. Imagine getting data through an API or something that isn't escaping it, and just assumes the data is clean.
  • g

    gorgeous-airport-54386

    05/08/2023, 7:19 PM
    escaping should happen at the time of presentation, because different contexts need different escaping
  • g

    gorgeous-airport-54386

    05/08/2023, 7:20 PM
    storing html entities in your database is not a good idea
  • r

    refined-waiter-90422

    05/08/2023, 7:21 PM
    Look at it the other way around: You can always un-escape HTML entities back to their normal form for code input boxes and stuff.
  • r

    refined-waiter-90422

    05/08/2023, 7:27 PM
    who knows where your data is going to end up with everything using electron nowadays.. would be awesome if everyone was 100% pro-active about security, but lol.
  • r

    refined-waiter-90422

    05/08/2023, 7:36 PM
    devs putting API output directly into the DOM = a tale as old as time.
  • g

    gorgeous-airport-54386

    05/08/2023, 7:36 PM
    couldn't be me
  • g

    gorgeous-airport-54386

    05/08/2023, 7:36 PM
    i won't so much as put two divs next to each other without a template system
  • f

    fancy-oil-15534

    05/11/2023, 4:17 AM
    Gimme productions example from Alpine X HTMx, 🙏 please
  • b

    bitter-baker-28217

    05/11/2023, 6:40 AM
    I am fecthing a json file using htmx. I want to use the array in the json and create a dropdown using alpine. Is there a quick example I can see?
  • b

    bitter-machine-55943

    05/11/2023, 12:51 PM
    Maybe BugBytes YouTube channel. He has 5-10 videos where he uses both HTMX and Alpine
  • b

    bitter-baker-28217

    05/11/2023, 12:53 PM
    Thanks, will check it out. Just realized that HTMX is meant to replace page elements/DOM. Not certain if it will interoperate with AlpineJS (e.g. work with x-data).
  • s

    strong-addition-37567

    05/11/2023, 5:18 PM
    You can have your backend return html that has alpine code in it and it should "just work". This assumes you can change your endoint to return html instead of json
  • s

    strong-addition-37567

    05/11/2023, 5:20 PM
    Just checked, we did add this:
    Copy code
    // activates any alpine directives in new content loaded by htmx
        htmx.onLoad((elt) => {
            Alpine.initTree(elt)
        })
    in our
    window.addEventListener("load", function() {
    so that alpine processes any new html loaded from htmx
  • k

    kind-jordan-22489

    05/19/2023, 7:18 PM
    hello, I'm having some issues listening to the htmx:pushedIntoHistory event. It works with document.addEventListener but when I do
    Copy code
    @htmx:pushedIntoHistory.document="doSomething()"
    it seems to ignore it. Maybe alpine gets confused by the : in the eventname? Any way around this?
  • a

    astonishing-teacher-48635

    05/25/2023, 10:25 PM
    is there a way to send a alpine variable with HTMX requests?
  • a

    astonishing-teacher-48635

    05/25/2023, 10:25 PM
    right now i just x-model the alpine var to a hidden input and then hx-include that input
  • m

    most-jelly-15242

    05/25/2023, 10:41 PM
    Was curious to see if I could come up with something and this worked:
    Copy code
    html
    x-data="{foo: 'bar'}"
    x-bind:hx-vals="JSON.stringify({'foo': foo})"
    I put that directly on a button and
    foo=bar
    is included in the request payload.
  • m

    millions-apartment-38225

    05/26/2023, 2:35 PM
    Late to the party, but just in case: Attributes are case-insensitive in Alpine, so you have to do something like this
    @htmx:pushed-into-history.camel
    https://alpinejs.dev/directives/on#camel