fancy-elephant-10660
01/18/2023, 9:48 AMaloof-farmer-99917
01/18/2023, 9:57 AMminiature-waiter-15357
01/18/2023, 11:24 AMminiature-waiter-15357
01/18/2023, 11:33 AMrich-coat-84078
01/18/2023, 1:34 PMlemon-rainbow-71647
01/18/2023, 8:14 PMrefined-waiter-90422
01/18/2023, 8:16 PMminiature-waiter-15357
01/18/2023, 8:35 PMbillions-easter-81130
01/21/2023, 1:53 PM<head>
. I do not use defer
for htmx (1.8.5), jQuery, justifiedGallery or lightGallery.
I try to only include libraries on an as-needed basis, so htmx is included on all pages, but jQuery, justifiedGallery and lightGallery are only included in my gallery page's <head>
.
To render the gallery, as per the libraries' documentations, I put the following code below my images:
html
<script type="module">
$("#lightgallery_77877f03-bb81-4d96-8e0d-c87c52b6b622").justifiedGallery({
rowHeight : 200,
}).on('jg.complete', function () {
lightGallery(document.getElementById('lightgallery_77877f03-bb81-4d96-8e0d-c87c52b6b622'), {
selector: '.image-tile',
plugins: [lgThumbnail],
speed: 500,
download: true,
licenseKey: '0000-0000-000-0000',
});
});
</script>
When I visit my gallery page directly (i.e. copy and paste URL into browser and press enter), everything works as expected - even with an empty browser cache to start with.
When I visit my gallery page via a boosted link instead, on my first visit with a fresh browser cache, the gallery is not rendered correctly: Neither justifiedGallery nor lightGallery work at all. I get the following error in my browser console:
ReferenceError: Can't find variable: $
in Safari or Uncaught ReferenceError: $ is not defined
in Firefox. The stack trace below that error refers to htmx.js, starting with line 1735. That line reads parent.insertBefore(newScript, script);
and is part of function evalScript(script)
.microscopic-winter-35952
01/27/2023, 5:09 PMimport django_filters
from django_filters import DateFilter
from .models import CheckingStatus, Participant
from django.db.models import Q
class ParticipantFilter(django_filters.FilterSet):
class Meta:
model = Participant
fields = '__all__'
views.py
def display_view(request):
myFilter = ParticipantFilter(request.GET, queryset=Participant.objects.all())
data = myFilter.qs
return render(request, 'display.html', {'data': data, 'myFilter': myFilter})
HTML
<body>
<form method ="get">
{{myFilter.form}}
<button class "btn btn-primary" type = "Submit"></button>
</form>
<br><br>
<div id="table-results" hx-get="/display" hx-trigger="every 2s">
<table border="1" class="table table-dark table-hover">
<thead>
<th>First_name</th>
<th>Last_name</th>
<th>Age</th>
<th>Checking Status</th>
<th>Time</th>
<th>Date</th>
</thead>
{% for k in data %}
<tr>
<td>{{k.first_name}}</td>
<td>{{k.last_name}}</td>
<td>{{k.age}}</td>
<td>{{k.checking.checking_status}}</td>
<td>{{k.checking.time}}</td>
<td>{{k.checking.date}}</td>
</tr>
{% endfor %}
</table>
</div>
</body>
Thanks for your timerich-coat-84078
01/30/2023, 12:45 PMpurple-exabyte-65527
01/30/2023, 8:28 PMminiature-lizard-24702
01/31/2023, 10:32 PMminiature-lizard-24702
01/31/2023, 10:34 PMcrooked-winter-42525
02/02/2023, 8:26 PMmagnificent-camera-86904
02/03/2023, 7:15 PMlittle-plumber-64748
02/05/2023, 7:41 PMbillions-architect-49743
02/10/2023, 10:26 AM{% block content %} <- Works targeting this
{% block fragment %} <- Can't target this without hitting an error
{% endblock fragment %}
{% endblock content %}
bitter-monkey-50309
02/10/2023, 5:48 PMbrief-cartoon-61118
02/10/2023, 9:57 PMbrief-cartoon-61118
02/10/2023, 9:57 PM<button hx-swap="outerHTML" hx-target="login_form" type="submit" value="Submit" </button>
brief-cartoon-61118
02/10/2023, 10:01 PMself.helper.attrs = {
# Redirecting on the save to signup page again
"hx-post": reverse_lazy("signup"),
# To replace/swap the form with the information returned by django
"hx-target": "#signup-form",
# Ajax swap to replace the outer HTML (Avoiding placing html inside the target - form inside form)
"hx-swap": "innerHTML",
}
brief-cartoon-61118
02/11/2023, 8:33 AMmagnificent-camera-86904
02/11/2023, 2:38 PMjs
function countCharacters() {
function count(input, count) {
const charCount = count.querySelector(".char-count");
charCount.textContent = input.value.length;
input.addEventListener("input", () => {
charCount.textContent = input.value.length;
});
}
const titleInput = document.querySelector("#id_title");
const titleCount = document.querySelector("#title-count");
count(titleInput, titleCount);
}
window.onload = countCharacters;
Given this Django template. The first element displays the number of characters in the value
field of the second element.
html
<p class="card-text">
<span class="text-success" id="title-count">Title Characters: <span class="char-count"></span></span>
</p>
<input type="text" name="title" value="I am a 25 character title" class="form-control" autofocus="" maxlength="250" required="" id="id_title">
Ideally, I could see myself using something like hx-post
to send the title to a view. Then the view would count the characters and send back a number. I would then use something like hx-swap
to swap out the textContent of the char-count
element.
The only problem is that I don't know how I could make it so the element keeps updating with new content as the user types (basically listen to a keyUp event).magnificent-camera-86904
02/12/2023, 4:55 AMpy
def count_characters(request):
title = request.POST["title"]
character_count = len(title)
return HttpResponse(character_count)
TEMPLATE
html
<p class="card-text">
<span class="text-success" id="title-count">Title Characters: <span class="char-count"></span></span>
</p>
<input autofocus="" class="form-control" hx-include="#id_title" hx-post="/count-characters/" hx-target=".char-count" hx-trigger="load, input" id="id_title" maxlength="250" name="title" required="" type="text" value="HELLO WORLD!">
magnificent-camera-86904
02/12/2023, 7:58 AMeager-psychiatrist-68229
02/12/2023, 8:20 AMeager-psychiatrist-68229
02/12/2023, 8:21 AMeager-psychiatrist-68229
02/12/2023, 8:22 AMeager-psychiatrist-68229
02/12/2023, 8:23 AM