Feature: Support both Free-Text and Multiple-Choice question types
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
function toggleVorschlagType(type) {
|
||||
const mcGroup = document.getElementById("mcOptionsGroup");
|
||||
const antwortLabel = document.getElementById("antwortLabel");
|
||||
const antwortHelp = document.getElementById("antwortHelp");
|
||||
|
||||
if (type === "multiple_choice") {
|
||||
mcGroup.classList.remove("hidden");
|
||||
antwortLabel.innerText = "Richtige Antwort (die korrekte Option):";
|
||||
antwortHelp.innerText = "Diese Antwort wird zusammen mit den falschen Optionen zufällig für den Spieler angeordnet.";
|
||||
} else {
|
||||
mcGroup.classList.add("hidden");
|
||||
antwortLabel.innerText = "Richtige Antwort:";
|
||||
antwortHelp.innerText = "Unser System gleicht Tippfehler und Groß-/Kleinschreibung automatisch ab.";
|
||||
}
|
||||
}
|
||||
|
||||
async function submitSuggestion(event) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -5,6 +21,7 @@ async function submitSuggestion(event) {
|
||||
const frage = document.getElementById("frage").value.trim();
|
||||
const antwort = document.getElementById("antwort").value.trim();
|
||||
const tipp = document.getElementById("tipp").value.trim();
|
||||
const qType = document.getElementById("q_type").value;
|
||||
const submitBtn = document.getElementById("submitBtn");
|
||||
const resultBox = document.getElementById("resultMessage");
|
||||
|
||||
@@ -13,19 +30,36 @@ async function submitSuggestion(event) {
|
||||
return;
|
||||
}
|
||||
|
||||
let falscheAntworten = [];
|
||||
if (qType === "multiple_choice") {
|
||||
const w1 = document.getElementById("wrong1").value.trim();
|
||||
const w2 = document.getElementById("wrong2").value.trim();
|
||||
const w3 = document.getElementById("wrong3").value.trim();
|
||||
falscheAntworten = [w1, w2, w3].filter(x => x.length > 0);
|
||||
|
||||
if (falscheAntworten.length === 0) {
|
||||
alert("Bitte gib bei Multiple-Choice mindestens eine falsche Antwortmöglichkeit an.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerText = "✨ Vorschlag wird übertragen...";
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
name: name || "Gast",
|
||||
frage: frage,
|
||||
antwort: antwort,
|
||||
tipp: tipp || null,
|
||||
question_type: qType,
|
||||
falsche_antworten: falscheAntworten
|
||||
};
|
||||
|
||||
const res = await fetch("/api/suggestions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name: name || "Gast",
|
||||
frage: frage,
|
||||
antwort: antwort,
|
||||
tipp: tipp || null
|
||||
})
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
@@ -39,6 +73,7 @@ async function submitSuggestion(event) {
|
||||
`;
|
||||
resultBox.classList.remove("hidden");
|
||||
document.getElementById("suggestionForm").reset();
|
||||
toggleVorschlagType("text");
|
||||
} else {
|
||||
resultBox.innerHTML = `
|
||||
<div class="alert alert-danger">
|
||||
|
||||
Reference in New Issue
Block a user