Skip to content

Commit 93ce2c1

Browse files
bugerclaude
andauthored
Fix critical HTMX target error in flashcard creation (#4)
The flashcard modal was targeting #flashcards-list but topic pages use #topic-flashcards-list, causing HTMX targetError when creating flashcards from topic pages. This fix makes the HTMX target context-aware: - Topic pages: target #topic-flashcards-list - Unit pages: target #flashcards-list Users can now create flashcards from topic pages without HTMX errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 470b373 commit 93ce2c1

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

resources/views/flashcards/partials/flashcard-modal.blade.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
hx-post="{{ route('units.flashcards.store', $unit->id) }}"
2929
@endif
3030
@endif
31-
hx-target="#flashcards-list"
31+
hx-target="{{ isset($topic) ? '#topic-flashcards-list' : '#flashcards-list' }}"
3232
hx-swap="innerHTML"
3333
hx-on::before-request="console.log('HTMX: Flashcard form submission starting...', event.detail)"
3434
hx-on::after-request="console.log('HTMX: Flashcard form submission completed', event.detail); if(event.detail.xhr.status >= 200 && event.detail.xhr.status < 300) { setTimeout(() => { const modal = event.target.closest('.fixed'); if(modal) { console.log('Removing flashcard modal...'); modal.remove(); } }, 100); }"
@@ -324,11 +324,15 @@ class="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-med
324324

325325
<!-- JavaScript for dynamic form behavior -->
326326
<script>
327-
let choiceCount = 0;
328-
329-
// Modal form response is now handled by HTMX events
330-
331-
function toggleCardTypeFields(cardType) {
327+
// Avoid global variable conflicts by scoping variables but keeping functions global
328+
(function() {
329+
// Private variables to avoid conflicts
330+
let modalChoiceCount = 0;
331+
332+
// Modal form response is now handled by HTMX events
333+
334+
// Make functions global so they can be called from HTML
335+
window.toggleCardTypeFields = function(cardType) {
332336
// Hide all card-specific fields
333337
const fieldGroups = ['basic-fields', 'multiple-choice-fields', 'true-false-fields', 'cloze-fields', 'image-occlusion-fields'];
334338
fieldGroups.forEach(group => {

0 commit comments

Comments
 (0)