How I added an AlpineJS click counter to my HTMX-powered website

Поділитися
Вставка
  • Опубліковано 25 січ 2025

КОМЕНТАРІ • 5

  • @ahmadumar9387
    @ahmadumar9387 8 днів тому +1

    i love this combination htmx with alpineJS

  • @nightshade427
    @nightshade427 23 дні тому +2

    wonder of its possible to add the x-data and event to the container of the chceckbexes and let it bubble up to keep track of count, so that way it doesnt have to be added to all the individual checkboxes?

    • @HAMYLABS
      @HAMYLABS  23 дні тому

      Yeah that is possible! I tried that first and it worked fine but you could basically click anywhere under the div container and it would count as a "click". I thought that kind of defeated the point cause it doesn't feel like it's actually counting box clicks.
      When I added it to the boxes directly and saw it only incurred another ~0.2kb I figured it was worth it.

    • @nightshade427
      @nightshade427 23 дні тому +1

      should be able to check if it's a checkbox and increment, maybe something like
      x-on:click="$event.target.type === 'checkbox' && count++"

    • @HAMYLABS
      @HAMYLABS  16 днів тому +1

      Oh that's a really good idea! I think that would work and cut down on markup payload size. Will try it.