https://htmx.org logo
Join Discord
Powered by
# 🔥-django-htmx
  • m

    mysterious-toddler-20573

    01/14/2022, 2:55 PM
    ah,
    a form can't be inside a tr
    , my old friend, we meet again
  • b

    blue-gold-89534

    01/14/2022, 3:28 PM
    hm ... everything besides the trigger works
  • m

    mysterious-toddler-20573

    01/14/2022, 3:29 PM
    I bet if you inspect the dom, the form element isn't even there
  • b

    blue-gold-89534

    01/14/2022, 3:29 PM
    yes it is there. But I encountered many cases where this fails ...
  • b

    blue-gold-89534

    01/14/2022, 3:30 PM
    for example if I swap anything including a
    <tr>
  • b

    blue-gold-89534

    01/14/2022, 3:31 PM
    but the code like I posted it works in general (besides the JS function trigger)
  • m

    mysterious-toddler-20573

    01/14/2022, 3:32 PM
    I have seen people put the form in the first
    td
    and then use this to associate the input properly: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form
  • b

    blue-gold-89534

    01/14/2022, 3:34 PM
    before doing it like this I had the form around the whole tbody ... that also worked ... but looked strange 🙂
  • b

    blue-gold-89534

    01/14/2022, 3:44 PM
    soooo you would recommend something like this:
    Copy code
    html
    <table>
        <tr id="editProductRow">
            {% for field in form.visible_fields %}
                <td><input form="htmxform" id="...">{{ field }}</td>
            {% endfor %}
            <td class="text-end">
                <form id="htmxform"
                      hx-post="{% url 'update' pk %}"
                      hx-target="#editProductRow"
                      hx-encoding="multipart/form-data"
                      hx-swap="outerHTML">
                    <button type="submit"
                            class="btn btn-success"
                            hx-trigger="click[showEditButtons()]">
                         OK
                    </button>
                </form>
            </td>
        </tr>
    </table>
  • m

    mysterious-toddler-20573

    01/14/2022, 3:46 PM
    I am not sure I would say I recommend it, but I think that's how HTML works when you want a form spread across tds within a tr
  • m

    mysterious-toddler-20573

    01/14/2022, 3:47 PM
    I might switch to divs and use styling to get a table-like effect, just to avoid dealing w/ the whole issue
  • b

    blue-gold-89534

    01/14/2022, 3:47 PM
    Yes I had that ... but styling is just soooo much easier with a table 😦
  • m

    mysterious-toddler-20573

    01/14/2022, 3:47 PM
    😑
  • m

    mysterious-toddler-20573

    01/14/2022, 3:47 PM
    the year is 2060
  • b

    blue-gold-89534

    01/14/2022, 3:47 PM
    I like tables.
  • m

    mysterious-toddler-20573

    01/14/2022, 3:47 PM
    i love tables
  • m

    mysterious-toddler-20573

    01/14/2022, 3:48 PM
    i just wish HTML treated them more flexibly
  • b

    blue-gold-89534

    01/14/2022, 3:50 PM
    sorry, I thought it was kind of mandatory to bring in a meme at some point
  • b

    blue-gold-89534

    01/14/2022, 3:51 PM
    I do not abandon my tables. Whenever I did that, and went down the hellish
    <div>
    way I had to pay the price in despair and frustration and !importants 😦
  • m

    mysterious-toddler-20573

    01/14/2022, 3:51 PM
    many such cases
  • m

    mysterious-toddler-20573

    01/14/2022, 3:51 PM
    it's easy: first we simply wage a hostile takeover of the w3c...
  • b

    bland-coat-6833

    01/14/2022, 3:51 PM
    display: table
    ?
  • b

    blue-gold-89534

    01/14/2022, 3:53 PM
    sorry. I did not want to start a meme war 😦 I just needed to vent a little bit of my frustration over my whole table idea to turn out not as great as I hoped it would.
  • b

    blue-gold-89534

    01/14/2022, 3:55 PM
    where is the application form?
  • b

    blue-gold-89534

    01/14/2022, 4:01 PM
    with this approach neither my form, nor my hx-trigger work 😦
  • b

    blue-gold-89534

    01/14/2022, 4:11 PM
    is it viable to just put the form over the whole table body?
  • p

    plain-kangaroo-26043

    01/14/2022, 4:22 PM
    @User maybe not use a after all, just add the hx-* attributes to that element and use hx-include to inject the fields (which I think you had originally). Using a form might be easier in most cases but clearly it's problematic in a table.
  • b

    blue-gold-89534

    01/14/2022, 5:32 PM
    thx to @User I solved the problem like this:
    Copy code
    html
    <table>
        <tr id="editProductRow"
            hx-target="#editProductRow"
            hx-encoding="multipart/form-data"
            hx-swap="outerHTML"
            hx-include="#editProductRow"
            hx-trigger="click[showEditButtons()] target:#submitbutton">
            {% for field in form %}
                <td>{{ field }}</td>
            {% endfor %}
            <td class="text-end">
                <button type="submit"
                        class="btn btn-success"
                        id="submitbutton">
                     OK
                </button>
            </td>
        </tr>
    </table>
  • b

    best-garage-8297

    01/14/2022, 6:52 PM
    Does hx-include work for you?
  • b

    blue-gold-89534

    01/14/2022, 6:53 PM
    yes!
1...404142...100Latest